Customize RankMath Breadcrumbs Text

#85827
  • Resolved Ahsan
    Rank Math free

    I want to add some text after some of my custom post type (CPT) posts. The breadcrumb is different from the title of the post. Is there any way to solve this?
    Suppose my post title is “Samsung Galaxy Note 20 Ultra 5G”. The breadcrumb is “Home > Mobile > Samsung Galaxy Note 20 Ultra 5G”. I want to add some text at the end of the breadcrumb title, like “Home > Mobile > Samsung Galaxy Note 20 Ultra 5G at Best Price”. Is there any way to do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    Yes there is a way, you just need to customize the following filter and add it to your theme functions.php:

    
    /**
     * 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 ) {
    	return $crumbs;
    }, 10, 2);
    

    Hope this helps you. Thank you.

    Ahsan
    Rank Math free

    Can you please give me a “code snippet”?

    Hello,

    Here is an example to modify the breadcrumb value to get the value of the custom field.

    /**
     * this is an example to remove the second item in your post breadcrumbs
     * 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 ) {
            // Check if we are viewing single posts
    	if(is_singular('post')){	
                    // Apply here your custom login to generate the final
                    // element of the breadcrumb (the breadcrumb title)
                    $newBreadcrumbTitle = "example";
                    // The last element in the $crumbs array is the post's
                    // breadcrumb title, so we have to update it:
                    $crumbs[count($crumbs)-1] = $newBreadcrumbTitle;
    	}
            // And return the breadcrumbs
    	return $crumbs;
    }, 10, 2);
    

    This is just a format of how to, for further customization please seek the help of a developer

    Hope that helps. If you have any further question(s), please let us know. Thank you.

    Ahsan
    Rank Math free

    Its only showing first letter of of the $newBreadcrumbTitle

    Hello,

    We can try and see if we can assist. Could you share the exact code you are using so far, you can use pastebin and share the link.

    Looking forward to helping you. Thank you.

    ​​​​​​

    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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Customize RankMath Breadcrumbs Text’ is closed to new replies.