How to Remove Parent Category from Breadcrumb of CPT?

#207094
  • Resolved Amit K
    Rank Math free

    Hi Rank Math Team!

    I have turned it off General Setting > Breadcrumbs > Show Category(s),
    By doing this the parent product category was removed from the breadcrumb of the child product category page but i am not able to remove the parent page from the breadcrumb of the posts that i have created with the custom post type plugin.

    [Eg: Home >> Cake >> Chocolate Cake]
    I don’t want parent category Cake in custom post type pages.

    Kindly help me how to remove the parent page from the breadcrumb.

Viewing 1 replies (of 1 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting the support and sorry for any inconvenience that might have been caused due to that.

    Paste the below filter code inside your active theme’s function.php file.

    /**
     * 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')){	//replace post with your postype
    		//Unset elements with key 1
    		unset($crumbs[1]);
                    $crumbs = array_values($crumbs);
    		return $crumbs; 
    	}
    	return $crumbs;
    }, 10, 2);

    I hope that helps. Thank you, and please don’t hesitate to contact us anytime if you need further assistance.

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

The ticket ‘How to Remove Parent Category from Breadcrumb of CPT?’ is closed to new replies.