Removing a breadcrumb using filters and replacing

#521567
  • Resolved Steve
    Rank Math free

    Good day

    I am using the Flatsome theme with Rank Math integration. Love Rank Math!!

    I have a custom portfolio page set in Flatsome as /portfolio.

    The breadcrumb path displays as “Portfolio (/featured_item/) > Portfolio Item Name”
    (This has been overlooked by the Flatsome Devs…when using Rank Math breadcrumb shortcode, the custom Portfolio page is not written into the breadcrumb path).

    I have used the following filter in the functions file to rewrite /featured_item/ to my custom link.

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$post_type = get_post_type(get_queried_object());
    	
    	if ($post_type == 'featured_item') {
    		$crumbs[1][0] = 'Portfolio';
    		$crumbs[1][1] = 'https://mydomain.com/portfolio'; // Change this on the live website to match the correct URL
    		$crumbs[2][0] = get_the_title();
    	}
    
    	return $crumbs;
    }, 10, 2);

    However, the breadcrumb now displays as:
    “Portfolio (/featured_item/) > Portfolio (My custom link) > Portfolio Item Name”

    How do I remove the first “Portfolio (/featured_item/) >” so that only “Portfolio (My custom link) > Portfolio Item Name” displays?

    Many thanks!!

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

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

    Please try applying the following filter instead to see if that works for you:

    add_filter( 'rank_math/frontend/breadcrumb/items', function( $crumbs, $class ) {
    	$post_type = get_post_type(get_queried_object());
    	
    	if ($post_type == 'featured_item') {
    		$crumbs[0][0] = 'Portfolio';
    		$crumbs[0][1] = 'https://mydomain.com/portfolio'; // Change this on the live website to match the correct URL
    		$crumbs[1][0] = get_the_title();
    	}
    	return $crumbs;
    }, 10, 2);

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

    Thank you.

    Steve
    Rank Math free

    Hi Sakib,

    Thanks very much – this works perfectly. Appreciated.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

You must be logged in to reply to this ticket.