WooCommerce: Wrong breadcrumbs displayed

  • Author
  • #24452



    I´m working on a website where I´m using posts that are in multiple categories. However, when I click on a menu item that leads to the correct lists of posts, the breadcrumbs show the first category of the first post displayed; but not the category I clicked on.

    That means, lets say I have several posts in both categories, “English” and “Something Else”. If I click on “Something Else” in the menu, the breadcrumb shows “Home -> English”; Just because the category “English” is alphabetically listed before “Something Else” and the first post is in both categories.
    This is confusing because the user didn´t click on “English”. Also, the URL still says “.\category\something-else”

    Is there a way to change that?


    • This topic was modified 2 years, 10 months ago by  Zed. Reason: updated title for clarity

    Cryout Creations Team

    Wordpress has no way of knowing which links you clicked on to get to that post, so it displays the first category (alphabetically) in which the post is found.

    Posts shouldn’t be placed in several categories if you care about what your breadcrumbs display. Try this plugin and see if it helps you in any way.

    • This reply was modified 4 years, 11 months ago by  Zed.

    If you like our creations, help us share by rating them on WordPress.org.
    Please read the available documentation and search the forums before posting.

    David B

    When I set the site up in January with Mantra, the breadcrumbs were all correct.
    Now breadcrumbs are wonky on the blog only.
    The Blog page shows Domain >> Home (not Blog)
    If I open a specific post, it shows domain >> Books >> Postname

    It displays it this way if I click on the post title, a Recent posts list link, or the Continue Reading link. If I go into a category, it displays the path to that category and continues with the correct category if I open one of the posts in the Category list. If I open a post via Archives, it shows Books path above again.

    Books is the name of a Page in the top menu (not adjacent) and the name of my second category, not the first.
    At first I thought this may be a bug in Excerpts as I’d recently changed to using that. But when I turned that off, it didn’t change the above.



    David B

    Apologies, I see this is a known issue in another thread (of several)


    Jonathon J

    WordPress has no way of knowing which links you clicked on to get to that post, so it displays the first category (alphabetically) in which the post is found.

    The latter part of this statement is correct, the first part is debatable. I have this similar problem, where I have a product in WooCommerce that needs to be in a certain three categories, however, the same category is showing up in the breadcrumbs no matter the means of arriving at the product. I also needed the image of the category accessed from to display above the product description, so again I needed to determine from which category archive the product had been accessed by. Thankfully, WordPress does have a way to determine which link was used to access a page: wp_get_referer().

    wp_get_referer() returns the url of, you guessed it, the referring URL. In this case, it’d be the category archive page that the user was viewing. In order to achieve my goal, I gathered an array of the categories associated with the product/post, obtained the URL of the previous page, looped through each category and checked to see if the category slug existed in the referring URL. If false, then I continued through the loop. If true, then I could persist with the rest of my code to display the specific category image instead of all three at the same time or even the wrong one. I’m about to try applying this same principle to adjusting the breadcrumbs as well. I’ll let you know what I come up with. My code is below for reference if you think it’ll help.


    Jonathon J

    Yep, it worked. I know you weren’t specifically using WooCommerce, but I’ll post up my code anyway in case it helps you or someone else. I copied the WooCommerce templates/global/breadcrumb.php file over to my theme’s directory woocommerce/global/breadcrumb.php. Then I replaced the portion of their code for single pages that are of type ‘product’:

    with my code instead:

    Same concept as I mentioned before. I just had to replace their main_term variable to the referring term instead. Hope this helps!


    Cryout Creations Team

    I’m glad you found a solution.
    You should suggest this change to the Woocommerce team, as you’re editing plugin files to correct behaviour.
    I don’t believe we can bundle other plugins’ files to our theme.

    If you like our creations, help us share by rating them on WordPress.org.
    Please read the available documentation and search the forums before posting.

    Simon Vincent

    Do you think this would be possible for normal wordpress posts and/or custom post types?



    Jonathon J, Your solution worked perfect for a while, but not anymore, maybe is has to do with updates, but I don’t now when this problem occured: the trail showes like this now:
    Home / THUIS / Tuinmeubelen / Applebee tuinmeubelen / Applebee AIR lounge / THUIS / Tuinmeubelen / Applebee tuinmeubelen / THUIS / Tuinmeubelen Applebee Air SOFA

    When it should be:
    Home / THUIS / Tuinmeubelen / Applebee tuinmeubelen / Applebee AIR lounge / Applebee Air SOFA

    Is there a simple way to fix this?





    Have you managed to find a solution for this for breadcrumb.php version 2.3.0?



    Hi Jonathon,

    can you find a solution for new version of WooCommerce breadcrumb.php? (2.3.0)
    In new version there is no such code that you posted above 🙁



    I would also be very interested in knowing if this can be done – we’d like to change breadcrumbs and also filter the WP menu ideally.

    We came across this plugin https://www.perfectseourl.com/ which does a lot of what we want to do (cleaner URL structure too), but find the site somewhat sketchy with a WooThemes theme/logo rip-off and no information about the people/company building the plugin, or the plugin past/future.



    We had another look at this and merged the code above with the new breadcrumb file. If anyone is interested, it’s here http://pastebin.com/0PtSbjFT

    After the $wrap_before, we cut in with Jonathon’s code, merging the is_single() && get_post_type() == ‘product’ ), so it only shows on single product pages, otherwise it uses the general WooCommerce breadcrumbs. Works well for us, perhaps it can help someone else.



    After reading your post @karl, I tried, but this wasn’t working for me. I bought the Perfectseourl plugin two days ago hoping its all okay, and yesss it works! Haha.. Can’t explain how happy we are with our shop now! It wasn’t cheap, but seems like the best solution we tried the last months.. Even after updating, to the latest version 2.3.13 all perfect!



    Nice job on the updated solution @Karl. Very much appreciated!



    I copied and pasted the code provided by karl:

    No deal, it doesn’t work for me.

    Is there something I’m missing here?

    Still the product is in category 1 2 & 3.

    If the customer gets to the product via Category 3, the breadcrumb still shows category 1.



    Correction to my issue here.

    I’m using Woocommerce, but the breadcrumbs are generated by the Yoast Seo plugin.

    Any ideas how to fix this, very frustrating and losing days on end over this.

    Thanks guys.




    @ GerBear @karl, it doesn’t work anymore.

    Can someone provide another solution?




    All use cache, so i guess this will never work? Is fragment caching needed to do this?


    Joris Witteman

    I’ve created an updated version of breadcrumb.php that works better with multiple nested categories on a product: http://pastebin.com/raw/bemM8ZNF

    Paste this into a new file at /wp-content/themes/your-theme/woocommerce/global/breadcrumb.php



    Great! Thank you man!


    Cryout Creations Team

    I strongly suggest creating a child theme to place that file in to avoid losing it on the next theme update.

    If you like our creations, help us share by rating them on WordPress.org.
    Please read the available documentation and search the forums before posting.

    veritas techsoft

    hi..plz help me i want to category name in variable but still call in woocommerce_breadcrumb(home) this function on product page plz check in this page http://tailord4u.com/product/dark-black-fabric-2/ …help me thank you in advance

Viewing 23 posts - 1 through 23 (of 23 total)

The topic ‘WooCommerce: Wrong breadcrumbs displayed’ is closed to new replies.