Remove the breadcrumbs in wordpress using hook - php

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.

Related

Removing the WooCommerce sidebar the correct way - TwentySeventeen?

I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.

How to add_action to Woocommerce hook?

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 :)

Calling a wordpress plugin in the header with a hook

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.

How to remove a php hook from a Wordpress theme

I'm trying to remove some hooks so that product categories don't show up on the homepage (of a Wordpress Storefront child theme).
I have the following code in my functions.php, which isn't working:
/**
* REMOVE SECTIONS ON HOMEPAGE
*/
add_action( 'init', 'remove_storefront_on_sale_products', 10 );
function remove_storefront_on_sale_products () {
?>
remove_action( 'homepage', 'storefront_on_sale_products', 60 );
<?php
}
Your code aint working because your line remove_action() is located outside of the php-tags.
Remove ?> and <?php in your above code and you should be fine.
First of all wordpress has not any action like "homepage" so you need to verify which action you are calling so if you want to remove function output only from homepage then you can do it by conditionally and secondly you didn't write proper php code, To achieve this you can write following in method.
if(!is_home()){
//Do stuff here if it is not homepage
}
OR
if(get_the_ID()!=101){ //101 your page id in which you don't want to show this
//Do stuff here if it is not homepage
}
I hope this may help you.

Wordpress - how to add a code snippet to <head> of each page

I want to add some code to the head of each page that loads using a plugin that I build. What is the proper hook for this and the proper way of doing it? Thanks a lot
For those looking for a sample code, here it is:
add_action( 'wp_head', 'YOUR_SCRIPT_IN_HEAD_FUNCTION' );
function YOUR_SCRIPT_IN_HEAD_FUNCTION() {
echo '<script>
// some code
</script>';
}
To add JS code, use the wp_enqueue_script() function - put your call in a function which gets added to the filter 'wp_enqueue_scripts'.
To add HTML, write a function to render whatever code you need and put it onto the wp_head filter. As in add_action('wp_head', 'your_function');
Does that help?

Categories