Renew Theme > Breadcrumb issue

Hi there, I have a strange issue with breadcrumbs and it seems like a bug. I have a series of posts in a category… and when I am in that category, the breadscrumb correctly shows the parent category… BUT - when I am in the individual posts of that category, it only shows the top level breadcrumb, which is the Blog Home page …it should be showing the category. Links and logins in hiffen post, thx so much.

Hi @kirk74,

It was set that way by default because a post can be added on multiple categories. Please check this thread for guidance.

Hope this helps.

Thanks, that worked, the parent category is showing in single post ow .

BUT, it still needs tweaking because the blog home link (Latest News) is now not showing on single posts, but it IS showing when parent category is chosen … so this is inconsistent, what line can I add please to also include the blog home link on the single posts’ breadscrumbs.

Thx so much

Hey @kirk74,

Did you remove the code from your child theme’s functions.php file?

File editing is not allowed. We cannot check the code in your dashboard

add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2);

function post_parent_trail ($crumbs, $args) {
  if ( is_singular('post') ) {

    $category = get_the_category( get_the_ID() );
    if ( count( $category ) > 0 ) {
    $crumbs[1]['label'] = $category[0]->name;
    $crumbs[1]['url'] = get_category_link( $category[0]->term_id );
    
   unset($crumbs[2]); //to make sure category won't duplicate

    }
  }
  return $crumbs;
}

Please put back the code so that we can check the breadcrumb.

Hi thanks, I didn’t remove the code, which is why the parent category IS now showing for the single posts breadcrumbs.

I can provide FTP if you need to access this, but this is my entire theme functions.php … there ar eno errors I donlt tink which s why it is working … it just needs 1 extra step…

<?php // ============================================================================= // FUNCTIONS.PHP // ----------------------------------------------------------------------------- // Overwrite or add your own custom functions to X in this file. // ============================================================================= // ============================================================================= // TABLE OF CONTENTS // ----------------------------------------------------------------------------- // 01. Enqueue Parent Stylesheet // 02. Additional Functions // ============================================================================= // Enqueue Parent Stylesheet // ============================================================================= add_filter( 'x_enqueue_parent_stylesheet', '__return_true' ); // Additional Functions // ============================================================================= // hiding the Issues categry for the blog feed (because it is only used as source for Essential Grid function x_exclude_cat_from_blog($query) { if ($query->is_home() && $query->is_main_query()) { $query->set('cat', '-35'); } } add_action('pre_get_posts', 'x_exclude_cat_from_blog'); //Hide categories from WordPress category widget function exclude_widget_categories($args){ $exclude = "35"; $args["exclude"] = $exclude; return $args; } add_filter("widget_categories_args","exclude_widget_categories"); // so that it correctly show th INETERVEW etc ategory breadcrumb when on individual posts add_filter('x_breadcrumbs_data', 'post_parent_trail', 9999999, 2); function post_parent_trail ($crumbs, $args) { if ( is_singular('post') ) { $category = get_the_category( get_the_ID() ); if ( count( $category ) > 0 ) { $crumbs[1]['label'] = $category[0]->name; $crumbs[1]['url'] = get_category_link( $category[0]->term_id ); unset($crumbs[2]); //to make sure category won't duplicate } } return $crumbs; } I feel like there is just one line that needs to be added to your script to get the blog home to show in the single posts, the way it does on the category archive pages. Thx.

Hi @kirk74,

Thank you for that information. Please try using this code instead:


function post_parent_trail ($crumbs, $args) {
  if ( is_singular('post') ) {

    /* blog page */

    $crumbs[1]['label'] = 'Latest News';
    $crumbs[1]['url'] = 'https://thelastpostmagazine.com/latest_news/';

    $category = get_the_category( get_the_ID() );
    if ( count( $category ) > 0 ) {
    $crumbs[2]['label'] = $category[0]->name;
    $crumbs[2]['url'] = get_category_link( $category[0]->term_id );
    

    }
    $crumbs[3]['label'] = get_the_title();

  }
  return $crumbs;
}



Hope this helps.

that actually just makes it the same as what it was doing by default with the custom coding (ie - it doesn’t show parent category on single posts) … it’s OK I have decided I don’t mind it working like this… as they can get to parent category though the meta link … thx

You are most welcome. :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.