Rank Math Breadcrumbs: Parent Page for a Post Type
Shows a regular page before custom post type entries in Rank Math breadcrumbs, such as Home > Our Team > Jane Doe.
Opens WPIDE on
Code
// Post type => ID of the page to show before it.
$wpide_rm_crumb_parents = array(
'team' => 42,
);
add_filter( 'rank_math/frontend/breadcrumb/items', function ( $crumbs ) use ( $wpide_rm_crumb_parents ) {
if ( ! is_array( $crumbs ) || ! is_singular( array_keys( $wpide_rm_crumb_parents ) ) ) {
return $crumbs;
}
$page_id = (int) $wpide_rm_crumb_parents[ get_post_type() ];
if ( $page_id && 'publish' === get_post_status( $page_id ) ) {
array_splice( $crumbs, 1, 0, array( array( get_the_title( $page_id ), get_permalink( $page_id ), 'hide_in_schema' => false ) ) );
}
return $crumbs;
} );
Notes
Map each post type to the ID of the page that acts as its parent.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.