Add child category in breadcrumbs

#143646
  • Resolved Antonio
    Rank Math free

    Hi there.
    I would know if is possible to add child category inside breadcrumbs.
    My URLS are so structured: example.com/parent-category/post-title/
    I have several child category, but the URL works just with parent category; I don’t want change URL (!!!).
    Is there a way to add child category too in post’s breadcrumbs?
    Where the URL is:
    example.com/parent-category/post-title/
    the breadcrumbs could be:
    Home > Parent category > Child category > Post title
    Thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hello,

    Thank you for getting in touch.

    IN that case you would need to customize you breadcrumbs in the front end adding the child categroy 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;
    }, 10, 2 );

    Please note you may need dev assistance to make this work.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Antonio
    Rank Math free

    Thanks for your answer.
    I tried the code but doesn’t change anything.
    Should I perhaps change something in the code to add child category into breadcrumbs?

    Hello,

    Have you enabled this option in the breadcrumbs settings already?

    Please let us know.

    Antonio
    Rank Math free

    Yes, enabled.
    And it works fine if I set “primary” the child category, and in the URL reports child category:
    example.com/category-parent/category-child/post-title/
    But I need not change URL.
    Thanks for your time, sorry for the trouble.

    Roel John
    Rank Math business

    Hello,

    Thank you for contacting Rank Math.

    Can you share a sample of the post URL you want to change? If you can share your access too so we can help to change a URL.

    Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.

    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    Thank you, and looking forward to your update.

    Antonio
    Rank Math free

    The URL includes just one category, the parent; what I would like to do.

    Corrige: the URL I would keep and I yet have.
    I would change just the breadcrumbs, and add to these the child category.

    Roel John
    Rank Math business

    Hello,

    Please see the screenshot for the sample URL and breadcrumbs. Is this what you want to achieve?
    Breadcrumbs

    Please add the code in functions.php to remove the child category in the URL.

    
    function wpse147453_remove_child_categories_from_permalinks( $category ) {
        while ( $category->parent ) {
            $category = get_term( $category->parent, 'category' );
        }
    
        return $category;
    }
    
    add_filter( 'post_link_category', 'wpse147453_remove_child_categories_from_permalinks' );
    

    Please make sure your Show Category(s)is On/Activate in Rank Math > General Settings > Breadcrumbs > Show Category(s).
    ShowCategory

    We hope this helps resolve your issue. Please let us know if you still need helps.

    Thank you.

    Antonio
    Rank Math free

    Thanks a lot!
    It works very fine, I was searching to modify Breadcrumbs, but with your code, I keep the same URL I have, then is what I was searching to do, and setting “Make term primary” the child category it works as I want.
    This plugin has a lot of customization possibility.
    Thanks to everyone for your time -:)

    Febby
    Rank Math free

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Antonio
    Rank Math free

    Sure, I will do.
    Thanks again -:)

    Febby
    Rank Math free

    Hello,

    Thank you for that, we really appreciate it.

    I will close this ticket for now.

    Feel free to open a new ticket if you encounter any more issues or if you have any more questions.

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

The ticket ‘Add child category in breadcrumbs’ is closed to new replies.