admin管理员组

文章数量:1125387

I’d like to get the breadcrumbs to show the category path on single posts. On the subcategory pages, I’ve got Blog>Category>Subcategory which is perfect. Example here:

However I’m unable to achieve this on single posts, where it just shows Blog>Post title. Example here:

Can you help, please?

Many thanks, Micheal Kean

I’d like to get the breadcrumbs to show the category path on single posts. On the subcategory pages, I’ve got Blog>Category>Subcategory which is perfect. Example here: https://mechanicalmentor.com/engineering/industrial-robotics

However I’m unable to achieve this on single posts, where it just shows Blog>Post title. Example here: https://mechanicalmentor.com/robot-programming-languages

Can you help, please?

Many thanks, Micheal Kean

Share Improve this question edited Dec 29, 2023 at 16:42 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 29, 2023 at 12:51 Micheal KeanMicheal Kean 1 1
  • Breadcrumbs aren't part of WordPress core, so this is a question for the support team theme or plugin you're using to provide them. – Pat J Commented Dec 29, 2023 at 15:09
Add a comment  | 

2 Answers 2

Reset to default 1

Default Wordpress doesn't have any breadcrumbs.

My guess is that your breadcrumbs are added by the plugin Rank Math (which seems to be installed on your site). So just go to the settings for your plugin and add categories to the breadcrumbs.

really it depends on the theme you are using. Please backup your site before trying any of these changes. You can possibly add them like this:

  • Open your theme functions.php file
  • Add this code
function wpb_custom_breadcrumbs() {
    // Breadcrumbs for single post
    if (is_single()) {
        global $post;
        $categories = get_the_category($post->ID);
        if ($categories) {
            $output = '<a href="' . get_permalink(get_option('page_for_posts')) . '">Blog</a> &raquo; ';
            foreach ($categories as $category) {
                $output .= '<a href="' . get_category_link($category->term_id) . '">' . $category->name . '</a> &raquo; ';
            }
            $output .= get_the_title();
            return $output;
        }
    }
    // Your existing breadcrumb code here for other page types...
}


Then find and edit your single.php file and add this code where the breadcrumb displays:

<?php echo wpb_custom_breadcrumbs(); ?>

Or

echo wpb_custom_breadcrumbs(); 

本文标签: Categories Not Showing in breadcrumbs in posts