Breadcrumb for Hirerchial Custom Post-type

#604683
  • Resolved Anonymous
    Rank Math free

    Hi RankMath,
    I am Using Rankmath. It’s The best SEO Plugin.

    I want my Breadcrumbs to be Like This

    Home >> Brand Name>> Parent page >> Child page

    *Brand name is a custom taxonomy

    I have added the Brand name to the breadcrumb By selecting the primary taxonomy from Title and meta section.

    How Can I Add the parent page to the breadcrumb

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.

    In this case, please try adding and customizing this filter to your site to add the parent page in the breadcrumbs:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	global $post;
    	$post_type = get_post_type();
    	if ($post_type == 'custom_post_type') { //change the value inside '' to your actual CPT name
    		$parent = get_post_parent();
    		if($post->post_parent) {
    			$crumbs[2][0] = get_the_title($parent);
    			$crumbs[2][1] = get_the_permalink($parent); 
    			$crumbs[3][0] = get_the_title();
    			return $crumbs;	
    		}
    	}
    	return $crumbs;
    }, 10, 2);

    And here’s a guide to adding the code to the website:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

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

The ticket ‘Breadcrumb for Hirerchial Custom Post-type’ is closed to new replies.