To get the value in header section - wordpress

I started to develop a plugin and i write the code bellow
add_filter('get_header', 'my_postslide');
It is calling the function in body part, but now i want to get the value in the header part.
It means in the <header> </header> part.Please let me know what the appropriate hook for call the value in the "<header> </header>" part.

Use the wp_headhook. see here in WordPress codex : http://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

Related

Elementor - adding custom code right after the <head> tag

Not sure if this is only problem for Elementor full width template, but it seems to override theme header.php. I tried achieving my goal by using elementor custom code feature, but it adds my code somewhere in middle of the tag.
What is the propper way of adding my own custom code as the first thing that is after the element?
You are right Elementor overrides the theme's header.php file so importing your code to this file is not effective. You need to add custom function to earn your goal. With the wp-head action you could add the code right into your header and Elementor will not override it.
Add this code to the functions.php file od your active theme.
add_action('wp_head', 'custom_head_function');
function custom_head_function(){
?>
YOUR HEADER CODE HERE
<?php
};
UPDATE - If you want to set your code at the top
As sephsekla mentioned in comment, there is a way to set the priority into your action to get it to the top. Try to set value to -999. So, choose a very low number and if there is no other lower number in your plugin or theme you will go straight to the top.
add_action('wp_head', 'custom_head_function', -999);
function custom_head_function(){
?>
YOUR HEADER CODE HERE
<?php
};
Elementor now supports custom code (javascript, html, etc) and supports the specific use of elements in the head of the page.
What you are looking for you can find at the Wordpress Dashboard> Elementor > Custom Code . Then you will be able to add a custom code to the head: https://elementor.com/help/custom-code-pro/

Wordpress output using custom url

I've been using WP_Route to create some custom urls as:
domain.com/players/playerID
If I use wp_send_json with a query result it works fine, but I would like to print that result.
If I do an :
get_header();
echo "<h1>".$player->name."</h1>";
get_footer();
I get:
NAME
OOPS! THAT PAGE CAN’T BE FOUND
any clues?
How could I force WP to don't run content hooks/whatever ?
PS: Wp_die() adds another header and body tag after the "good content".
<body id="error-page">
<p></p>
</body>
If you are using Anthony Budd's WP_Route, then don't. It's not a finished product (it doesn't work). It's surprising that the author has pushed this class without even testing it. Other users have made pull requests, presumably fixing some of the bugs and glaring omissions, but it seems that the author isn't responding so consider the project dead. There are forks, however, that might be in working condition.
You should probably just exit; in your handler.
When you call the wp_die() function it typically outputs a full HTML document, including the <html>, <head> and <body> tags as well as some CSS and an error message, and this is probably not what you want in your handler.
As the WP_Route class is written, your handler is executed on the WordPress init hook.

Want to remove "background" text

How can I remove the text background=""> from my Wordpress site?
The address is https://www.mybestroadbikes.com
Thanks!
You need to delete if from the page source itself.
Here is where is the extra String
Hope this helps :)
EDIT:
I am not sure how you page is structured in WordPress but you can try when you are on the home page just click Edit Page in the top menu.
After that you will ed up in a Dashboard window with some RichTextBox on it. On the right side you have to option to switch to Text instad of Visual. When you do that I think you will be able to locate the extra String and remove it:
Please check your body tag in header.php
The tag must must have been closed incorrectly.
You've got an issue with whatever mechanism you have used to insert Google Tag Manager. Use another method to whatever you have used or check your syntax because there's a syntax error with it. You can easily embed the script in the header using the hook wp_head.
function child_theme_head_script() { ?>
<script>
//Script here
</script>
<?php
}
add_action( 'wp_head', 'child_theme_head_script' );

Wordpress shortcode does not work

I'm trying to create a simple shortcode function that would work in a link like this:
href="http://www.website.com">[short_code]
Please note, I had to remove the a tag because it wouldn't show. I want to be able to change the anchor text of a link with a single edit across multiple pages/posts.
to accomplish this, this is what I've done:
I've added include 'myshortcodes.php'; to functions.php file and created a file called myshortcodes.php
within that file I have the following code:
<?php
add_shortcode('hw', 'hello');
function hello() {
return 'Click Here For More Info';
}
Now when I put [hw] in href="http://www.website.com">[hw] it does work on my local wp install, however, when I do the same on my live server, it doesn't work, no matter what I do. It returns [hw] instead of 'Click Here For More Info'. Any ideas why? Thanks!
Maybe problems with php interpreter on server side.
Check if your server side doing include right.
Below and above your shortcode function place echo with something, and if it will echoes on your site, then we need to dig deeper.
And if it will not echoes, than the problem is in include function.

Add dynamic content before the loop in Wordpress

I'm developing a content slider for Wordpress and I would know how is possible to put this content slider (as html content) into the body before the loop.
I tried to filter the content with add_filter('the_content', 'functionName), but I get the content slider before each post.
If you use add_filter('the_content'), your function will be called everytime the content of a post is output, whether a single post or a series of posts in a loop. If you need to "hook" before any post content is output in a page, the only dynamic parts of all WP themes you can reach are get_header() or get_sidebar() (or event get_footer). So your best luck would be not to use a filter with the content, but an action, with get_header, like this :
add_action('get_header', 'your_function'); // Add priority & param args if necessary
The problem is that this gets executed before header.php is called, and usually, the body tag is opened in header.php...
That is if you cannot modify the theme itself. Otherwise, you can easily add an action in the theme itself and execute it where you want.
Another technique would be to add your html content after document is ready, through JavaScript which you can output in the footer.

Resources