• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to set the preferred category in breadcrumbs??

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

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

This topic is: not resolved

Tagged: breadcrumbs, Modify Breadcrumb Display, Multiple Categories

  • This topic has 5 replies, 5 voices, and was last updated 7 years, 7 months ago by sangfroidweb.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • December 23, 2012 at 11:35 am #7177
    Shawn Teo
    Member

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

    thanks for advice and merry christmas


    New launch Singapore | Property Launch | Singapore Property Listings

    December 23, 2012 at 12:14 pm #7182
    Susan
    Moderator

    Try this:

    http://my.studiopress.com/snippets/breadcrumbs/

    January 7, 2013 at 2:08 pm #10165
    Jason
    Member

    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?

    Thanks!


    Jason Larsen. Owner of Qoala Group.

    January 7, 2013 at 10:53 pm #10274
    wpsmith
    Member

    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

    October 27, 2015 at 1:14 pm #169236
    sangfroidweb
    Participant

    Hi!,
    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 http://www.wpstudioworks.com and building custom Genesis Child themes for businesses at http://www.sangfroidwebdesign.com 🙂

    October 27, 2015 at 2:32 pm #169244
    sangfroidweb
    Participant

    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 http://www.wpstudioworks.com and building custom Genesis Child themes for businesses at http://www.sangfroidwebdesign.com 🙂

  • Author
    Posts
Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble