I have this plugin https://fr.wordpress.org/plugins/wayne-audio-player/ that is called in the footer but i need it to be in my header.
I've managed to do that easily with some css.
But then i've noticed this line:
add_action('wp_footer', 'wayne_audio_player_markup');
So i tried this:
add_action('get_header', 'wayne_audio_player_markup');
But it doesn't seem to work. I would like to know if there's a way of calling this plugin in the header without css code.
You can do this:
remove_action('wp_footer', 'wayne_audio_player_markup');
add_action('wp_head', 'wayne_audio_player_markup');
With remove_action you can unregister any previously hooked functions.
Related
I simply want to add an action to an existing Woocommerce hook (woocommerce_after_cart in this case). After adding a function with add_action() and loading the page back up, my function doesn't run. Not until I manually do_action() does my function finally run. I just want to know why when I add the action originally, it's not being acknowledged.
I've already checked out Wordpress codex for hooks and seems like I'm doing everything correct. I'm adding the action in a custom theme, not functions.php but I've tried that too.
Full thing looks like this:
function abc() {
print_r("hello world");
}
add_action('woocommerce_after_cart','abc');
Hello world does not print on page load, only after I call do_action(), why?
In order for any add_action() to work a do_action() must be called.
The woocommerce_after_cart action is called in the template "/cart/cart.php"
https://github.com/woocommerce/woocommerce/search?utf8=%E2%9C%93&q=woocommerce_after_cart
In your theme or child theme do you have the file "/woocommerce/cart/cart.php"?
It could be that the WooCommerce cart template is being overridden and that the template does not have the <?php do_action( 'woocommerce_after_cart' ); ?> call.
I have tested your abc function and it works in a vanilla out of the box install of Woo and WP.
You need to add the <?php do_action( 'woocommerce_after_cart' ); ?> action to the cart.php template file.
Hope this helps :)
To remove the breadcrumbs I have a solution using css which I have used but I want to remove that using hook instead of css.
.breadcrumbs {
display:none;
}
Please let me know the hook to remove the breadcrumbs from all pages.
Hook to remove breadcrumb is following. Add following code in your theme's functions.php file.
add_action( 'init', 'd_remove_breadcrumb');
function d_remove_breadcrumb() {
remove_action( 'storefront_content_top', 'woocommerce_breadcrumb', 10);
}
I found out that I could go into its header-page file and just remove/comment it out.
It already had a do_action there, and if I then used a remove_action in functions.php, it came out an error.
Thank you all for using some time to answer and try to help, which made me think in some other way than I usually do.
I develop a plugin and need to add meta tags to the section.
I have spent about 1 hour and had found a lot of hooks, but all of them are bypasses. I don't want to turn my code in piece of ****, can sb tell me if there is normal way to add html to the ?
Thank you
It depends on which kind of content you want to include in <head>.
Scripts and styles need to be registered and/or enqueued using the proper WP functions:
wp_enqueue_script()
wp_enqueue_style()
You can hook this functions in wp_enqueue_scripts if you need them in your front-end (as I guess from your question) or admin_enqueue_scripts to have them available in admin area.
Any other type of content could be hooked up using the wp_head action hook:
function hook_metatag() {
?>
<meta name="description" content="Description">
<?php
}
add_action('wp_head', 'hook_metatag');
This will be echoed when the theme calls the wp_head() function.
The standard is to use the wp_head hook.
<?php
add_action( 'wp_head', function() {
echo '<meta ... />';
} );
Note: This works well for meta tags. However, if you're injecting styles or scripts, instead of printing those out yourself using wp_head, use wp_enqueue_script() or wp_enqueue_style().
I need to know how to take the output of a custom built Wordpress plugin and output it onto a specific page.
I know that I need to use the add_action() / add_filter() functions to call the function which outputs the plugins output when a wordpress hook function runs.
Currently I am using the 'the_content' hook.
This outputs my plugins output to all pages in my theme which call the the_content() function.
Which hook can I use to make the output only appear on a specific page.
Also
It would be useful to know how to create a page using my plugin.
Checkout is_page()
if (is_page(123)) {
// put your hooks here
}
put your code in a file inside plugin directory
then
use this
function page_directory()
{
if(is_page('123')){
$dir = plugin_dir_path( __FILE__ );
include($dir."custom/page.php");
die();
}
}
add_action( 'wp', 'page_directory' );
i've written a plugin which shortcodes can easily be used in every post and page. As this plugin can be useful in a sidebar as well i want to make the text widget usable for my shortcodes.
When i googled this i found out that i can use the add_filter() function to ensure that, but this is only possible if i have access to the theme's functions.php. But as i am the creator of the plugin and not of the theme, this is not usable for me.
Does anybody know how i can make a shortcode which is introduced with a plugin usable in the widgets section?
Thanks!
Open your theme's function file.
Find a free spot after the opening php tag that isn't part of a function.
add this:
if (!is_admin())
{
add_filter('widget_text', 'do_shortcode', 11);
}
save the file and you should be all set.
Open your page in edit mode.
Select your page location and line where you want to add short code.
Add code here and update..