How to remove parent category from Yoast breadcrumbs

I’m having a bit of hard time trying to get this one link/category disappear from my bredcrumb path.

The path goes as follows: home/customPostTypeCategory/subCategory/child/ , so what I need to get done is to get that customPostTypeCategory to go away.

Read More

So as a clearness, this is a Custom post type made with Types -plugin, and breadcrumbs are using SEO by Yoast breadcrumbs.

This could be done via CSS, but that is the last solution I’m willing to use.

Any clues, tips or tricks how to do this?

Thanks!

Related posts

Leave a Reply

3 comments

  1. add_filter( 'wpseo_breadcrumb_links', 'my_breadcrumb_filter_function' );
    function my_breadcrumb_filter_function( $crumbs ) {
        foreach( $crumbs as $i => $crumb ) {
            $term = get_object_vars($crumb['term']);
           if( isset( $term['parent'] ) && $term['parent'] != 0 ) {
    
            } else {
                $new_crumbs[] = $crumbs[$i];
            }
        }
        return $new_crumbs;
    }
    
  2. So I solved this by using jQuery and contains -selector.

    $( "#breadcrumbs a:contains('customPostTypeCategory')" ).removeAttr( "href" );

    This obviously removes only the link, so that the category name still stays.

    If the whole thing should be removed, then one could use the following:

    $( "#breadcrumbs a:contains('customPostTypeCategory')" ).css( "display", "none" );

    This did the trick for me, but it ain’t the solution I was looking and asking for.

  3. I had the same issue with a custom post type.

    After looking at the output of the array, I saw that array(1) was the archive, and what I believe you’re calling a category.

    This did the trick for me:

    function my_breadcrumb_filter_function( $crumbs ) {
    
        // replace "cpt" with your custom post type name 
        if(is_singular('cpt')) {
          $crumbs[1] = '';
        }
        return $crumbs;
    
    }
    add_filter( 'wpseo_breadcrumb_links', 'my_breadcrumb_filter_function' );