WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] Replacing WooCommerce breadcrumbs with Yoast SEO ones (17 posts)

  1. James
    Member
    Posted 1 year ago #

    Hi,

    Thought this should be simple, but can't find a solution anywhere after hours of searching so here goes...

    What I want to do is remove the default WooCommerce breadcrumbs and instead replace these with the WordPress SEO (Yoast) breadcrumbs. I have Yoast breadcrumbs on the rest of the site and would like to continue the same layout, structure and styling on the ecommerce pages too.

    I have Yoast breadcrumbs working fine elsewhere, but can't figure how to get them to show up on the WooCommerce pages. I found an article about replacing WooTheme breadcrumbs with Yoast ones (see here), but this doesn't work (i.e. no effect) for Woocommerce.

    Any ideas please?

    Thanks, James

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. James
    Member
    Posted 1 year ago #

    Ok, I think I've figured out a solution!

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    // Remove default WooCommerce breadcrumbs and add Yoast ones instead
    remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
    add_action( 'woocommerce_before_main_content','my_yoast_breadcrumb', 20, 0);
    if (!function_exists('my_yoast_breadcrumb') ) {
    	function my_yoast_breadcrumb() {
    		yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    	}
    }

    Very pleased with myself for that :)

    The first line of code removed the default WooCommerce breadcrumbs from all pages, then the other lines add in the Yoast ones in their place with the necessary formatting to keep them looking the same as the rest of the site.

    This goes in the custom functions.php of my theme.

  3. ssohl
    Member
    Posted 1 year ago #

    Where did you place these lines of code?

  4. James
    Member
    Posted 1 year ago #

    The above code went in my themes custom 'functions.php' file. Go to Appearnace > Editor in the menu, select your theme and then the custom functions file. Guess the details vary depending upon your theme and setup, but for me, functions.php is a file for pasting just this sort of over-ride code.

    Hope that helps.... James

  5. jantjebeton
    Member
    Posted 1 year ago #

    Hi,

    I use Woocommerce on WordPress and want to get the YOAST breadcrumbs. To be honest, not sure why. What is the benefit over the standard breadcrumbs which look pretty good to me?

    I did what you did but only got the breadcrumbs on the product pages. How can I get them also on the other pages?

    Hope you can help me.

  6. James
    Member
    Posted 1 year ago #

    Jantjebeton - the advantage for me of Yoast breadcrumbs over the standard ones is that you have more control over the way they are displayed. You can set the breadcrumb text for a given post / page (see the Advanced tab under the 'WordPress SEO by Yoast' settings on each page / post edit screen) so the breadcrumb is not fixed as the page / post title. So you can neaten the breadcrumb trail up considerably.

    Also, in my theme I found that the WooCommerce breadcrumbs were different to the WP ones elsewhere on my site in terms of layout, separator, style and format. By using the Yoast ones everywhere I got consistency of design and format.

    To add the Yoast breadcrumbs to all the other pages, follow the instructions on the 'Internal Links' section of the Yoast plugin settings in your WP admin area. There's some code that you need to add to your templates to get the breadcrumbs to show on the non-WC pages too.

    Hope that helps... James

  7. leeuwtje
    Member
    Posted 1 year ago #

    Thank you so much for the code.

    Unfortunately I have problems at my product pages:
    Fatal error: Call to undefined function yoast_breadcrumb() in /home/renatfb56/domains/haardonutkopen.nl/public_html/wp-content/themes/mystileori/mystile/functions.php on line 55

    Does somebody have a solution for this problem?

  8. James
    Member
    Posted 1 year ago #

    Do you have the WordPress SEO plugin installed and Yoast Breadcrumbs activated within that? See here:
    http://wordpress.org/extend/plugins/wordpress-seo/

  9. mashedspuds
    Member
    Posted 1 year ago #

    Hi James. Just to thank you for this solution. Managed to replace it with Yoast's breadcrumbs.

    Just on the off-chance that someone is using Thesis theme (2.x), just put the code into: Theme Functions (functions.php).

  10. robscott
    Member
    Posted 1 year ago #

    This code would go into Functions.php on almost any theme!

  11. ecoreng
    Member
    Posted 10 months ago #

    The code that @james wrote works great.

    I use yoasts breadcrumbs because they also include structured data which helps to get indexed nicely.

  12. videoink
    Member
    Posted 9 months ago #

    Yoast bredcrumbs not working: I have tried adding:
    // Remove default WooCommerce breadcrumbs and add Yoast ones instead
    remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
    add_action( 'woocommerce_before_main_content','my_yoast_breadcrumb', 20, 0);
    if (!function_exists('my_yoast_breadcrumb') ) {
    function my_yoast_breadcrumb() {
    yoast_breadcrumb('<p id="breadcrumbs">','</p>');
    }
    }
    to my functions.php page, but the woocommerce breadcrumbs are still there.
    I have SEO Yoast plugin installed, used internal links settings to create yoast breadcrumbs..NOTHING works. Any help would be greatly appreciated.
    I'm about to lose it..

  13. James
    Member
    Posted 9 months ago #

    The above code to remove the default Woo breadcrumbs and replace them with the Yoast ones is no longer working for me either :( I just can't seem to get rid of the Woo breadcrumbs, suspect this is something to do with my theme (Striking) since I think it happened after I installed an update which included some new breadcrumb functionality.

    Still trying to figure it out.... will report back if I find anything.

  14. julester75
    Member
    Posted 8 months ago #

    My functions.php file states categorically:

    <?php
    /*
    WARNING: This file is part of the core PrimaThemes framework.
    DO NOT edit this file under any circumstances.
    Please do all modifications in the form of a child theme.
    */
    require_once( TEMPLATEPATH.'/core/functions/setup.php' );

    With this being the case, any ideas where I should put this code? I also want to hide the search form from the bottom of my shop/products pages too, so advice on code to achieve this would be much appreciated...

  15. Leon Korteweg
    Member
    Posted 8 months ago #

    Put this in the functions.php of your child theme:

    // Replace WooThemes Breadcrumbs with Yoast breadcrumbs
    add_action( 'init', 'mp_breadcrumbs' );
    function mp_breadcrumbs() {
        remove_action( 'woo_loop_before', 'woo_breadcrumbs', 10 );
        add_action( 'woo_loop_before','mp_yoast_breadcrumb', 20, 0);
        function mp_yoast_breadcrumb() {
            if ( function_exists('yoast_breadcrumb')  && !is_front_page() ) {
                yoast_breadcrumb('<p class="breadcrumbs">','</p>');
            }
        }
    
    }
  16. kajari
    Member
    Posted 5 months ago #

    not working for me - not even with the yoast woocommerce seo paid extension - have written to support and waiting for their reply

  17. Herbert
    Member
    Posted 4 months ago #

    This worked for me... Using Woo Canvas and WooCommerce

    // Replace WooThemes Breadcrumbs with Yoast breadcrumbs
    add_action( 'init', 'hh_breadcrumbs' );
    
    function hh_breadcrumbs() {
        remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
        add_action( 'woocommerce_before_main_content','hh_yoast_breadcrumb', 20, 0);
        function hh_yoast_breadcrumb() {
            if ( function_exists('yoast_breadcrumb')  && !is_front_page() ) {
                yoast_breadcrumb('<p class="breadcrumbs">','</p>');
            }
        }
    
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic