Breadcrumbs and Custom Post Type Title

#402192
  • Hello! Using the breadcrumbs PHP code in our theme templates… when RankMath breadcrumbs is showing our custom post type, it is showing it as a singular term (service) whereas the custom post type section is /services/ in the URL and should be plural. Can you please tell me what is the custom post type term the breadcrumb uses to pull in?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Prabhat
    Rank Math agency

    Hello,

    Thank you for contacting the support and we regret the inconvenience caused.

    By default, we do not include the post type name in the breadcrumbs. Could you confirm if you’re using any additional filters to add the post type name to the breadcrumbs of the CPT?

    Also, as the URL is correct, please double check the singular and plural names of the CPT and update them if required and see if that helps.

    Let us know how that goes.

    Thank you.

    Thanks for your reply. It looks like the breadcrumbs are using the title in the link text. Is it possible to have them use the slug instead? This is for both regular pages and the CPT on our site.

    Prabhat
    Rank Math agency

    Hello,

    Could you share some example URLs with these breadcrumbs so that we can have a closer look and suggest you a solution?

    Looking forward to helping you.

    Thank you.

    Hi, so access to our dev site requires IP white listing so I’ll share some screengrabs if these will work… the RankMath breadcrumb code is under the page title where the house icon is.

    This screengrab shows a page with a URL slug of “locations” and a longer page title. We would like the breadcrumb link text to use the URL slug instead of the page title:
    https://snipboard.io/uKC0ks.jpg

    This screengrab shows a custom post type “service” with a URL slug of “services” and page title of “services” We would like the breadcrumb link text to use the URL slug of “services” instead of the CPT single identifier
    https://snipboard.io/YQvKGy.jpg

    Hello,

    Please try applying this filter code to your theme’s functions.php file:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        if(is_singular('locations')){ /* IF YOU ARE USING RANK MATH'S STANDARD LOCATIONS CPT, USE THIS INSTEAD: is_singular('rank_math_locations')*/
            global $post;
            $page_slug = $post->post_name;
            $crumbs[count($crumbs)-1][0] = $page_slug;
        }
        return $crumbs;
    }, 10, 2);

    As for the service page, as mentioned by my colleague, Rank Math’s generation of breadcrumbs depends on the configuration of the post type you have created. Could you please ensure that you have set the plural text of the CPT Services as “Services”?

    You may modify the filter above a bit if you wish to change the breadcrumbs text forcibly.

    Looking forward to hearing an update from you.

    Thank you! This is perfect and exactly what I was looking for!

    Anas
    Rank Math business

    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.

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

The ticket ‘Breadcrumbs and Custom Post Type Title’ is closed to new replies.