0

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

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

2 Answers 2

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.

0

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(); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.