Remove category breadcrumbs

#551732
  • Resolved IMK
    Rank Math free

    Attached is a screenshot: https://prnt.sc/N2lZY_LivtOi

    I have checked that from the Rank Math settings, there is an option to uncategorise breadcrumbs. However it does not exist.

    Would you be so kind to explain me, what would be the correct code snippet to remove the category.

    Thanks in advance

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thanks for contacting us, and sorry for any inconvenience that might have been caused due to that.

    Please make sure you’ve chosen None as Primary Taxonomy at Rank Math > Titles & Meta > Posts [OR any other post type you want to apply the settings].
    https://rankmath.com/kb/titles-and-meta/#primary-taxonomy

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

    Thank you.

    IMK
    Rank Math free

    Hello Sakib,

    It works. Thank you very much.

    However I’m curious how I could remove it via a code snippet, leaving the category option enabled.

    Is it possible to know?

    Thanks in advance

    Hello,

    Yes, that’s possible. You can try adding the following filter to remove categories from your breadcrumbs:

    add_filter('rank_math/frontend/breadcrumb/items', function ($crumbs, $class) {
    	
    	$categories = array_map( function ( $category ) {
    		return $category->name;
    	}, get_the_category() );
    
    	foreach($categories as $category){
    	
    		$key = array_search($category, array_column($crumbs, '0'), true);
    		if (isset($key)) {
    			unset($crumbs[$key]);
    			$crumbs = array_values($crumbs);
    		}
    	}
        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.

    Thank you.

    IMK
    Rank Math free

    Hi Sakib!

    It works properly.

    Thank you very much for your work and for helping people with less knowledge in programming.

    Keep up the good work

    Hello,

    Glad that helped.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

You must be logged in to reply to this ticket.