Breadcrumbs problems with child pages and CPT

#540004
  • Resolved Thorsten R.
    Rank Math free

    Hi,

    today I have following problem and reading through the knowledge base just helped me out a very little bit. I set up a CPT without the use of an archive and categories. I provide a working permalink example inside the sensitive data where you can see that the breadcrumb on the page doesn’t show the full hierarchical structure. My structure is following:

    my-url.com/parent-page/child-page AND CPT SLUG/post-title

    In detail: the name of the static child page is the slug of the custom post type. At the beginning the parent page and the child page both never showed up inside the breadcrumb, then I found that article and now the child page / cpt slug is showing up inside the breadcrumb. But the parent page is still missing.

    Hope my problem is clear enough :))

    Thorsten

Viewing 3 replies - 1 through 3 (of 3 total)
  • Sorry, as my permalink was working all the time it just was about the breadcrumb that was not showing up correctly but it does right now with provided code above:

    Home >> static page >> cpt_slug >> cpt_post_title

    Hi, I could solve my request on my own as I found another article in your knowledge base. Here’s the solution:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$post_type = get_post_type(get_queried_object());
    	
    	if ($post_type == 'cpt_slug') {
    		$crumbs[1][0] = 'Name of static Page';
    		$crumbs[1][1] = 'https://my-url.com/page/'; // URL of static page
    		$crumbs[2][0] = 'CPT NAME';
    		$crumbs[2][1] = 'https://my-url.com/page/cpt_slug/'; // URL of CPT slug
    		$crumbs[3][0] = get_the_title();
    	}
    
    	return $crumbs;
    }, 10, 2);

    That return my permalink inside the breadcrumb:
    https://my-url.com/page/cpt_slug/cpt_post_title

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    We appreciate you sharing the code here and are glad that you have already managed to resolve the breadcrumbs structure.

    If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.

    Looking forward to helping you.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The ticket ‘Breadcrumbs problems with child pages and CPT’ is closed to new replies.