Remove Custom Post Type Base Link From Breadcrumbs

#26436
  • Resolved IlPizza G.G.Service
    Rank Math free

    Hi, in my website I’ve created a custom post type named “Product” and a related custom taxonomy named “Collection”.

    In my CPT single page, the breadcrumbs shows the base “Product”, the taxonomy “Collection” and the post name, but I would like to remove the base “Product”.

    So, now my breadcrumbs are:

    – Home > Product > Collection > Post Title

    My goal is to have:

    – Home > Collection > Post Title

    Thank you in advance!

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

    Thank you for contacting Rank Math today.

    Please head over to your WP Dashboard > Rank Math > General Settings > Breadcrumbs > Show Category(s) and disable this option.
    This will essentially hide the parent categories from the breadcrumbs.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hi Michael,
    I’ve tried but it didn’t work 🙁

    Maybe it didn’t work because “Product” is not a parent category, it’s the Custom Post Type base link…

    Have you any other idea? Maybe I should use some filter from https://rankmath.com/kb/filters-hooks-api-developer/?

    Thanks again 🙂

    Hello,

    Thank you for contacting Rank Math today.

    Yes this is also an option. You can use the following filter but it will need to be customized further to remove the breadcrumb items:

    /**
     * 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);

    Looking forward to helping you. Thank you.

    ​​​​​​

    Yes, I know it need to be customized… that’s why I asked for help 🙂
    Do you think you can help me and provide the code needed to remove CPT Base link? Or at least a complete example of this filter?

    Thanks again 🙂

    Hi there,

    Thanks for the follow up.

    Here is an example for illustration to remove the second item on the 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')){	
    		//Unset elements with key 1
    		unset($crumbs[1]);
                    $crumbs = array_values($crumbs);
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    I hope this info helps. Thank you.

    Yes, it helps me a lot 🙂
    Thank you very much, this is exactly what I needed!

    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/?rate=5#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 ‘Remove Custom Post Type Base Link From Breadcrumbs’ is closed to new replies.