CSS (or PHP) to remove first and last breadcrumb from single posts

#461669
  • Resolved Georgie Donno
    Rank Math free

    For context, I’m using two custom post types (directory listings and posts).

    For the directory listing pages, I want to keep the breadcrumbs as is.

    For the posts, I’d like to remove the “Home” and “Article Title” from the breadcrumb (so that only the two categories appear: primary + sub-primary)

    I’ve tried using CSS to remove the last breadcrumb (Article Title), but I don’t think CSS is the right way to go as the output is not ideal:

    .single-post .inside-article .rank-math-breadcrumb .last {
    display: none;
    }

    If you could guide me on which PHP filter to use I would really appreciate it!

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can try the following code snippet on your website to remove both the last and first item when the post type are articles:

    
    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
        if(get_post_type() == 'post') {
            array_pop($crumbs);
            unset($crumbs[0]);
        }
    	return $crumbs;
    }, 10, 2);
    

    ​​​​​​Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    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 ‘CSS (or PHP) to remove first and last breadcrumb from single posts’ is closed to new replies.