Support » Plugin: Yoast SEO » [Plugin: WordPress SEO by Yoast] Breadcrumbs reversed with hierarchical taxonomy

  • Resolved moikano


    I don’t know if there is a good reason, but the breadcrumbs order is reversed with the terms of a hierarchical taxonomy (WP SEO

    I solved by editing the function “get_term_parents()” in “wordpress-seo/frontend/class-breadcrumbs.php“:

    function get_term_parents($term, $taxonomy) {
    	$origterm = $term;
    	$parents = array();
    	while ($term->parent != 0) {
    		$term = get_term($term->parent, $taxonomy);
    		if ($term != $origterm)
    			$parents[] = $term;
    	// editing start //
    	if ( count( $parents ) > 1 ) {
    		$parents = array_reverse( $parents );
    	// editing end //
    	return $parents;

    If it is correct, I hope this change (or similar) will be applied in the next update.

    Thanks for the wonderful plugin!!! 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • This only somewhat works. It works when you visit a category page that is deeply nested, but for single post pages the categories still appear backwards :/

    Hi Chris,

    I suppose you’re using WP SEO (my report was for if so, joostdevalk has updated partially the code… instead of to reverse the order in the get_term_parents() declaration, he reversed the order “directly” in the source, but not for tax/category/tag archives;

    to solve this, you can simply to edit the original “wordpress-seo/frontend/class-breadcrumbs.php” on row #234 so:

    if ( is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0 ) {
    	$parents = $this->get_term_parents($term, $term->taxonomy);
    	// editing start //
    	$parents = array_reverse( $parents );
    	// editing end //
    	foreach($parents as $parent) {

    I hope you can to solve it 🙂

    Ahh, I see what you mean. I implemented your fix, and it seems to have worked, thanks so much!

    Strangely though, I’ve noticed that the only single post pages that display the entire breadcrumb path are posts filed under a third-level category within my “Music Reviews” category. Here is the category hierarchy I have set up…

    – Featured (for front page slideshow items)

    – Music
    —- Music Interviews
    —- Music News
    —- Music Reviews
    ——– Albums
    ——– Concerts
    ——– EP’s
    ——– Singles

    – Film
    —- Film Interviews
    —- Film News
    —- Film Reviews

    Posts filed under second-level categories like “Film Interviews” or “Music News” do not display that category in the breadcrumb path, they simply display the parent category “Music” or “Film”.

    Any ideas why this is happening? I can’t seem to figure it out :/

    Hi Chris,

    I’m glad you’ve solved 🙂

    about the other problem I don’t know: are you sure that you didn’t assign also parent categories to the post?

    to retrieve terms in the “main post type”‘s taxonomy (specified in the WP SEO Internal Links options), WP SEO Breadcrumbs uses wp_get_object_terms() that returns a list of terms in alphabetical order: the first in the list is the “parent” category of the post;

    for example:
    – with “Music” and “Music News”, “Music” is the post’s “parent”;
    – with “Music”, “Music Reviews” and “Singles”, “Music” is the post’s “parent”;
    – with “Music”, “Music Reviews” and “Concerts”, “Concerts” is the post’s “parent”;

    if this is your situation, the solution is very simple: assign posts to the “true” category only;

    I hope this answers your question 🙂

    Ah! You’ve done it again! Haha. I had all of the parent categories assigned as well. I changed it so the posts were only assigned to their “true” or deepest categories, like you said, and everything works perfectly.

    Thanks so much for all of your help!

    Plugin Author Joost de Valk


    Thx moikano 🙂

    I encountered the same thing. With the code of moikano I could correct the reverse order. Would be nice to be able to choose which order in the admin pages. Nice plugin by the way 😉

    Plugin Author Joost de Valk


    Just fixed the remaining sort issue as well.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: WordPress SEO by Yoast] Breadcrumbs reversed with hierarchical taxonomy’ is closed to new replies.