• Resolved VisedFAQ

    (@visedfaq)


    Hello there! We have two parent pages, which shouldn’t appear on breadcrumbs at all (on all subpages of those parents, this parent page shouldn’t appear), shouldn’t be indexed and should redirect to home page if accessed somehow. I managed to do the last two things (as well as remove them from sitemap), but I’m still struggling with breadcrumbs. I’ve tried two code snippets I’ve found on this forum, but they don’t work for me:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $items ) {
    	if ( is_page(2270) || is_page(313) ) {
    		return [];
    	}
    
    	return $items;
    } );
    
    add_filter('rank_math/snippet/breadcrumb', function ($entity) {
    	if (is_page(2270) || is_page(313)) {
    		return [];
    	}
    	return $entity;
    });

    Any suggestion on how to remove specific pages completely from the breadcrumbs?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @visedfaq,

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

    Please try applying the following filter to exclude a particular page from your breadcrumbs. The code below applies to your entire site breadcrumbs and works for a single page. You can just modify it according to your needs.

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) { $page = get_the_title( 123 ); //Replace the ID '123' with the one you want to exclude from breadcrumbs if ($page) { $i=0; while(count($crumbs) >= $i){ if($page == $crumbs[$i][0]){ array_splice( $crumbs,$i,1 ); }$i++; } } return $crumbs; }, 10, 2);

    Here’s how you can add filters/hooks to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Let us know how it goes. Looking forward to helping you.

    Thread Starter VisedFAQ

    (@visedfaq)

    @rankmathteam hello, thanks for your response. I’ll try it out soon, any chance you can send code example which accepts an array of such pages I need to remove, not just one page?

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @visedfaq,

    You can try the following filter instead of the above one to remove multiple pages from your breadcrumbs:
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    global $post;
    $page_ids = array( 1, 2, 3 ) ; //Add your page or post IDs here by replacing '1,2,3'
    foreach($page_ids as $page){
    $pages = (get_the_title( $page) );$i=0;
    while(count($crumbs) >= $i){
    if($pages == $crumbs[$i][0]){
    array_splice( $crumbs,$i,1 );
    }$i++;
    }
    }
    return $crumbs;
    }, 10, 2);

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Thread Starter VisedFAQ

    (@visedfaq)

    @rankmathteam this is perfect, thank you very much! I think this should be an option in the Breadcrumbs setting in the admin UI, just saying…

    Plugin Support Rank Math Support

    (@rankmathteam)

    Hello @visedfaq,

    Glad that helped.

    If it isn’t too much to ask for, would you mind leaving us a review here?
    https://www.ads-software.com/support/plugin/seo-by-rank-math/reviews/#new-post

    It only takes a couple of minutes but helps us tremendously.

    It would mean so much to us and would go a long way.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Remove specific pages from all breadcrumbs’ is closed to new replies.