How to set the preferred category in breadcrumbs??

Community Forums Forums General Discussion How to set the preferred category in breadcrumbs??

This topic is: not resolved

This topic contains 5 replies, has 5 voices, and was last updated by  sangfroidweb 4 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #7177

    Shawn Teo

    hi, How to set the preferred category in breadcrumbs when a post is assigned different categories?

    thanks for advice and merry christmas



    Try this:

    Susan @ One Happy Studio I offer theme customizations I tweet!
    I’ve taken up the challenge! – help me answer some of the unanswered posts



    I would also like to do something similar – but not set a single referred category, set a ‘dynamic’ category. For example, if a user clicks on “Category C” they might see posts / pages that are in only Category C, but those posts may also exist in other categories.

    If they click through to a specific post, I would like the breadcrumb to display the category that the user selected, not a default or ‘primary’ category. Is this possible?




    You need to install the sCategory Permalink plugin. Please let me know if it doesn’t work. However, there is built-in support in the Breadcrumbs function/class for you to accomplish this with this plugin.

    Travis Smith | Recommended StudioPress Developer & Contributor
    WP Smith | @wp_smith | GitHub

    Due to the forums, please paste code using Pastebin, JS Fiddle (for JavaScript) or GitHub.
    How to use Firebug for Designers by SixRevisions



    Susan points to the breadcrumb snippets page for this, but that page doesn’t address the original poster’s issue, which is my issue now. I guess this post is a few years old, so the snippet page may have had a solution previously, but unless I’m missing something, I don’t see any mention of a way to set a preferred category…. or am I missing something?

    Liz or Eddy @SangFroid Web — Customizing StudioPress themes at and building custom Genesis Child themes for businesses at :)



    In case this helps anyone else in the future…. I did some digging into the breadcrumb class and found a solution in the get_post_crumb function of the breadcrumb class. When the heirarchial_categories arg is set to true (default) the developers included support for a plugin: sCategory Permalink plugin (mentioned by moderator wpsmith, above) however that plugin hasn’t been updated in 6 years, so I’m avoiding like the plague. The developers still have the support in the class though, so we can use that. Basically it checks the post meta for the meta_key “_category_permalink”, which from the code I can tell contains the ID of a preferred category. Now that I knew that, I had 2 choices.. go through and create a meta value for each and every post… *yuk* or find a way to filter get_post_meta the return value of the get_post_meta function, which the get_post_crumb function uses to find out if that meta_value is set. Luckily WordPress has a filter we can use, get_post_metadata. So now if anyone comes knocking, looking for that meta_key in any post.. we can return what we want. Here’s the function I put together:

    // Filter breadcrumb category preference
    add_filter(‘get_post_metadata’, ‘preferred_category’, true, 4);
    function preferred_category($metadata, $object_id, $meta_key, $single){

    global $post;

    // is a value for our target meta_key being sought?
    if($meta_key == ‘_category_permalink’){

    // If the current post is checked with our preferred category, return that categoy’s ID as the metadata
    if( in_category( 5 , $post ) ){
    $metadata = 5;


    return $metadata;


    You just need to set the category ID to your preferred category id ( 5 for me in the example above ).

    It seems to be working. The only caveat is, if the developers decide to dump support for that meta_key, since the original plugin which was the impetus for it’s use seems to have been orphaned… this code will no longer work. So dear developers.. if you notice this post. Don’t discontinue support for _category_permalink. Thanks!

    I hope this helps anyone else looking for a default breadcrumb category!

    Liz or Eddy @SangFroid Web — Customizing StudioPress themes at and building custom Genesis Child themes for businesses at :)

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

You must be logged in to reply to this topic.