Rank Math Breadcrumb Customization – Snippet needed

#308881
  • Resolved Greenheartmedia
    Rank Math free

    Dear Staff,

    can you provide a Snippet for the following issue:

    I want the post title not to be displayed as final child. Instead i want to display a custom field which relies to ACF to make breadcrumbs more attractive.

    To make it more clear
    Actually it’s like:
    Home > Category > Subcategory > Post Title
    e.g. Brand > Pillow > Neck Pillows > The 5 Best Neck Pillows to reduce Neck Pain in 2021

    This is quite Long and should be more attractive.

    It should be like:

    Home > Category > Subcategory > Advanced Custom Field
    Brand > Pillow > Neck Pillows > The 5 Best Neck Pillows 2021

    Can you provide a snippet to hook on an ACF on final Breadbrumb instead of post title?

    Thank you.

    Kind regards,
    Daniel

Viewing 7 replies - 1 through 7 (of 7 total)
  • Chandni
    Rank Math free

    Hello,

    Thank you for contacting Rank Math, and sorry for any inconvenience that might have been caused due to that.

    You can use the following filter to modify the behavior of the breadcrumbs:
    https://rankmath.com/kb/filters-hooks-api-developer/#change-breadcrumb-settings

    We hope this information helps. Please let us know if you need help with anything else.

    Thank you

    Dear Chandni,

    Thank you for your quick reply. I already know this blogpost but actually iam not a developer so it would be great if you can help me with a specific snippet as requested.

    Thank you a lot.

    Kind regards,
    Daniel

    Hello,

    To modify the filter according to your site we will need to take a closer look at your posts. Please share the login details of your site so we can assist you further.

    Looking forward to helping you.

    Thanks.

    Dear Jaideep,

    actually to solve this request you don’t need access for the website cause this a very generic issue. I think i can make this a bit more easy to understand what iam exactly looking for.

    All we need to do is: replacing post title tag on the very end of every breadcrumb with a shortcode tag.

    e.g.
    Home > Category > Subcategory > Post Title (standard RankMath)
    should be
    Home > Category > Subcategory > Shortcode

    and this shortcode leads to a custom text field.

    Would be lovely if you can provide a snippet for that.

    Kind regards,
    Daniel

    Prabhat
    Rank Math agency

    Hello,

    You can modify and use the below code and see if this gives you the desired output:

    /**
     * Allow changing or removing the Breadcrumb items
     *
     * @param array       $crumbs The crumbs array.
     * @param Breadcrumbs $this   Current breadcrumb object.
     */
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        array_splice($crumbs, count($crumbs) - 1, 1);	
        $crumbs[][0] = get_field('field_name'); //Replace the field_name with the name of the custom field
        return $crumbs;
    }, 10, 2);

    Please replace ‘field_name’ with the custom field name on your website.

    You can follow this guide to add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how that goes.

    Thank you.

    Works perfect! Thanks a lot.

    Prabhat
    Rank Math agency

    Hello,

    We are super happy that we could address your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us 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 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.

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

The ticket ‘Rank Math Breadcrumb Customization – Snippet needed’ is closed to new replies.