Breadcrumbs

#196794
  • Resolved Asjad
    Rank Math free

    Hi, I want to know how can I add two categories in breadcrumbs? Like one is the primary category and other is secondary.

    For example, I have set primary category as shoes and secondary category is cross-trainer. Now, I want to show both categories in breadcrumbs. But it is only showing primary category i.e. shoes. Please help, how can I add both.

    Thanks in advance

Viewing 6 replies - 1 through 6 (of 6 total)
  • Cris
    Rank Math business

    Hello,

    Thank you for contacting us and I am very happy to assist you.

    From what I understand, you need to have a parent category and a child category in Breadcrumbs. Please correct me if I’m wrong.
    But if that is what you are after then you need to customize your breadcrumbs in the front end adding the child category using the following filter:

    /**
     * Filter to change the primary term output of the breadcrumbs class.
     *
     * @param WP_Term $term  Primary term.
     * @param array   $terms Terms attached to the current post.
     */
    add_filter( 'rank_math/frontend/breadcrumb/main_term', function( $current_term, $terms ) {
    	return $current_term;

    And please make sure this is enabled on your Breadcrumbs:

    I hope that helps and please do not hesitate to contact us back anytime if you require further assistance.

    Happy to help!

    Cheers,

    Asjad
    Rank Math free

    where should I add this code?

    Cris
    Rank Math business

    Hello,

    Thanks for getting back to us.

    I wasn’t able to mention where to add the code. My apologies.

    Please add the given code to your themes functions.php file.

    Please give it a try and let us know how it goes so we can assist you further.

    Cheers,

    Asjad
    Rank Math free

    Is the code correct? I am facing error:
    “Your PHP code changes were rolled back due to an error on line 43 of file wp-content/themes/kadence/functions.php. Please fix and try saving again.”

    I pasted this code”
    /**
    * Filter to change the primary term output of the breadcrumbs class.
    *
    * @param WP_Term $term Primary term.
    * @param array $terms Terms attached to the current post.
    */
    add_filter( ‘rank_math/frontend/breadcrumb/main_term’, function( $current_term, $terms ) {
    return $current_term; (this is line 43)

    Asjad
    Rank Math free

    Please reply

    Hello,

    Thank you for the update, and apologies for the delay.

    The filter needs to be customized based on your site’s structure, and it seems that the code is incorrect. Here’s the correct filter:
    https://rankmath.com/kb/filters-hooks-api-developer/#5-filter-to-change-the-primary-term-output-of-the-breadcrumbs-class

    However, the child category will only show in the breadcrumbs if it’s set up as the Primary Category for that specific product.

    Please also ensure that you are using the categories as your primary taxonomy in Rank Math > Titles & Meta > Products
    Primary Tax

    I hope that helps.

    Thank you, and please don’t hesitate to contact us anytime if you need further assistance with anything else.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Breadcrumbs’ is closed to new replies.