exclude custom post type ‘name’ from breadcrumbs

#393829
  • Resolved Iselin Fox
    Rank Math free

    I’ve created custom post types using jetengine plugin, for ‘products’. But would like for the breadcrumbs to not include the name of the custom post type, where it uses the singular name of the type (produkt). Instead I would like for the breadcrumbs to be like this: ‘Home’ – ‘parent category(ies) – ‘category’ – ‘title of product’ as it is with regular posts (they don’t start with ‘post’)
    Now the pages with custom post types have breadcrumbs like this: ‘home’ – ‘custom post type name’ – ‘parent category(ies) – etc etc.
    How can i change this? Tried adding this code to the function.php but it didn’t work..

    add_filter( ‘rank_math/frontend/breadcrumb/items’, function( $crumbs, $class ) {
    if (get_post_type() === ‘CPT Name’) {
    unset($crumbs[1]);
    return $crumbs;
    }
    return $crumbs;
    }, 10, 2);

    Here is link to post type page with breadcrumbs: http://staging.port-service.no/produkter/privat/garasjeporter/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with applying a filter to your breadcrumbs schema.

    I have edited the filter as below. Please check that it is displaying correctly

    
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	
    	if ( "produkter" === get_post_type() ) {
    		$crumbs[1] = $crumbs[2];
    		$crumbs[2] = $crumbs[3];
    		unset($crumbs[3]);
    		return $crumbs;
    	} 
    	return $crumbs;
    }, 10, 2);
    

    Hope that helps. Please let us know if you have questions.

    Perfect, thank you!

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

You must be logged in to reply to this ticket.