Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
These snippets are examples of how you can modify the Yoast SEO breadcrumb visual output. These snippets will not alter the breadcrumb schema output. Please consult the schema documentation to change the breadcrumb schema: https://developer.yoast.com/features/schema/api#to-add-or-remove-graph-pieces
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/*
* Remove the last breadcrumb, the post name, from the Yoast SEO breadcrumbs
* Previous breadcrumb link will become text
* Credit: Jason @ http://thejasonjones.com/wordpress-seo-breadcrumbs-tweaks/
* Last Tested: Jun 11 2018 using Yoast SEO 7.6.1 on WordPress 4.9.6
*/
add_filter( 'wpseo_breadcrumb_links', 'wpseo_breadcrumb_remove_postname' );
function wpseo_breadcrumb_remove_postname( $links ) {
if( sizeof($links) > 1 ){
array_pop($links);
}
return $links;
}
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/*
* Remove the last breadcrumb, the post title, from the Yoast SEO breadcrumbs
* Previous breadcrumb will remain linked
* Credit: David @ https://generatepress.com/forums/topic/how-to-hide-the-title-part-in-the-breadcrumb-im-using-yoast-seo/#post-614239
* Last Tested: Apr 11 2020 using Yoast SEO 13.4.1 on WordPress 5.4
*/
add_filter('wpseo_breadcrumb_single_link', 'remove_breadcrumb_title' );
function remove_breadcrumb_title( $link_output) {
if(strpos( $link_output, 'breadcrumb_last' ) !== false ) {
$link_output = '';
}
return $link_output;
}
@dustinleer
Copy link

dustinleer commented May 21, 2018

Modified this to target based on url. :)

<?php
add_filter( 'wpseo_breadcrumb_single_link', 'wpseo_remove_breadcrumb_link', 10 ,2);
function wpseo_remove_breadcrumb_link( $link_output , $links ){
	$page_src = $links['url'];
	$last_word = basename( $page_src );
	$text_to_remove = 'shop';

	if( $last_word == $text_to_remove ) {
	  $link_output = '';
	}

	return $link_output;
}
?>

@JohndeLange
Copy link

JohndeLange commented Aug 12, 2018

How do I change the yoast_seo_breadcrumb_remove_link.php to accept 2 words? I have a multilingual website using Products and Producten?

@sk0ch
Copy link

sk0ch commented Aug 21, 2018

add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);
function wpseo_remove_breadcrumb_link( $link_output , $link ) {

    $text_to_remove = [
    	'Products',
    	'Товари'
];

if ( in_array( $link['text'], $text_to_remove, true ) ) {
	return;
}

    return $link_output;
}

@meisterx2020
Copy link

meisterx2020 commented Nov 30, 2018

How can I delete 'Products' in Json-ld?
When I set yoast_seo_breadcrumb_remove_link.php, I can delete 'Products' in breadcrumbs frontend, but 'Products' still remain in Json-ld.

@KLarpen
Copy link

KLarpen commented May 3, 2019

@meisterx2020 I think it's late to answer, but may be useful for others.

With 'wpseo_breadcrumb_single_link' hook you may change only the front end breadcrumbs output (i.e., HTML markdown). The filter used in another generation process than JSON-LD.

With 'wpseo_breadcrumb_links' hook you may filter the source data of the breadcrumbs: both for front end and JSON-LD. Worth to mention that autogenerated array $links has another type of values than shown in 'Append link' example https://gist.github.com/amboutwe/ea0791e184668a5c7bd7bbe357c598e9#file-yoast_seo_breadcrumb_append_link-php

LINKS
Array
(
    [0] => Array
        (
            [text] => Home
            [url] => http://example.com/
            [allow_html] => 1
        )
    [1] => Array
        (
            [id] => 62
        )
    [2] => Array
        (
            [term] => WP_Term Object
                (
                    [term_id] => 33
                    [name] => Водоснабжение и канализация
                    [slug] => water-supply
                    [term_group] => 0
                    [term_taxonomy_id] => 33
                    [taxonomy] => category
                    [description] => 
                    [parent] => 0
                    [count] => 1
                    [filter] => raw
                )
        )
    [3] => Array
        (
            [term] => WP_Term Object
                (
                    [term_id] => 44
                    [name] => Кольца Евро железобетонные
                    [slug] => rings-caps-bottoms
                    [term_group] => 0
                    [term_taxonomy_id] => 44
                    [taxonomy] => category
                    [description] => 
                    [parent] => 33
                    [count] => 1
                    [filter] => raw
                )
        )
    [4] => Array
        (
            [id] => 1
        )
)

You're able to remove an item from breadcrumbs source completely or add/replace an item using the structure shown in examples.

$breadcrumb[] = array(
            'url' => 'your.new.url',
            'text' => 'Page Name',
        );

@Kan1221
Copy link

Kan1221 commented Nov 23, 2019

Is there way to change the parent category url to custom url.
Example :
Home >> Parent Category >> child category >> post
What I need
Home >> Parent Category >> child category >> post
I want to change parent category to custom one.

Thanks

@salpilk
Copy link

salpilk commented Dec 12, 2019

Any ideas how to change the pathway for posts of a particular category only? So all posts in my 'Current' category would link back to a URL page on my site, rather than to the Current archive page.

Many thanks

@egzonhassi
Copy link

egzonhassi commented Dec 12, 2020

Modified it to only remove the href link and keep the breadcrumb :

` add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);
function removeBreadcrumbLink($link_output , $link){
$link_output = str_replace('href="'.$link['url'].'"' , "" , $link_output);
return str_replace('data-wpel-link="internal"' , "" , $link_output);
}
function wpseo_remove_breadcrumb_link( $link_output , $link ){
$breadcrumbsLinkToBeRemoved = [
'Titles to be removed'
];
if(in_array($link['text'] , $breadcrumbsLinkToBeRemoved )) {
return removeBreadcrumbLink($link_output , $link );
}

    return $link_output;
}`

@newusernamedtimo
Copy link

newusernamedtimo commented Dec 19, 2020

Can someone help me to delete the subcategory in all breadcrumbs? I need this to custom display posts on my theme, but I dont want to have access the subcategory anywhere.

Example :
Home >> Parent Category >> child category >> post
What I need
Home >> Parent Category >> post

And on some other pages I need to remove the parent category as well:

Example :
Home >> Parent Category >> child category >> post
What I need
Home >> post

I thank you a lot.

@jmchasco
Copy link

jmchasco commented Dec 25, 2020

Looks like yoast_breadcrumb doesn't honor the toggle off for the category path prefix on breadcrumbs links.
Captura de pantalla 2020-12-25 a las 18 03 00
Any suggestion to fix this ? Ideally should be part of Yoast itself.

@kokoruz
Copy link

kokoruz commented Feb 17, 2021

I am wondering if there is a way to disable the parent link from the child page.

Home >> About >> Our Council

Technically 'About' is not a Page, its the parent menu item that leads to 'Our Council'

Right now I'm using jquery to remove the link. It's nice because my breadcrumbs are intact but I don't like that I see it flash for a second with the link before the jquery removes the href.

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

I've thought about using something like this

$content = preg_replace("/(.*?)</a>/","",$content);

but would need to really understand the plugin code to make something like this work.

@kokoruz
Copy link

kokoruz commented Feb 17, 2021

Your code does almost what I want. Your code removes the link completely. I just want it to remove the href. I still like having the path. I just don't want that parent item click able. Thanks!

add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);

function wpseo_remove_breadcrumb_link( $link_output , $link ){
$text_to_remove = [ 'About', 'Training'];
if ( in_array( $link['text'], $text_to_remove, true ) ) {return;}
return $link_output;
}

@kokoruz
Copy link

kokoruz commented Feb 17, 2021

I was able to figure my question out based on the previous responses. Thanks for sharing the initial post. Was very helpful.

add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);

function removeBreadcrumbLink($link_output , $link) {
$link_output = str_replace('href="'.$link['url'].'"' , "" , $link_output);
return str_replace('data-wpel-link="internal"' , "" , $link_output);
}
function wpseo_remove_breadcrumb_link( $link_output , $link ) {
if(strpos( $link_output, 'breadcrumb_last' ) !== false ) {$link_output = '';}
$breadcrumbsLinkToBeRemoved = ['About', 'Scouting', 'Training', 'Resources', 'Giving'];
if(in_array($link['text'] , $breadcrumbsLinkToBeRemoved )) {
return removeBreadcrumbLink($link_output , $link );
}
return $link_output;
}

@972creative
Copy link

972creative commented Apr 12, 2021

@korkoruz Both versions of your code remove the parent category completely, but I thought it should leave the category in the breadcrumb but just remove the href. Did I misunderstand, or is there a bug with your code?

@jackcarrington
Copy link

jackcarrington commented Aug 2, 2021

Hello,

Please can someone help me.

My goal is to have the category/archive URL show in my breadcrumb path for posts tagged in specific archives only.

So a rule to say if the post is tagged 'news' include the /news/ breadcrumb.

I don't want to include the category breadcrumb rule sitewide as some posts have multiple categories.

But for my /blog/ section and /news/ section, I would like the posts breadcrumb path to parent said archive page.

@amboutwe
Copy link
Author

amboutwe commented Aug 2, 2021

This is not the proper place to request support. Please check out our extensive help section or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team.

@foteinitaramonli
Copy link

foteinitaramonli commented Mar 26, 2022

Hi,
I am using the following code ,to remove "Shop" from breadcrumb in Schema.org but does not work. Any suggestions? Thank you beforehand.
add_filter( 'wpseo_breadcrumb_single_link' ,'wpseo_remove_breadcrumb_link', 10 ,2);

function wpseo_remove_breadcrumb_link( $link_output , $link ){
    $text_to_remove = 'Shop';
  
    if( $link['text'] == $text_to_remove ) {
      $link_output = '';
    }
 
    return $link_output;
}

@amboutwe
Copy link
Author

amboutwe commented Mar 31, 2022

@foteinitaramonli These snippets are examples of how you can modify the Yoast SEO breadcrumb visual output (image below). These snippets will not alter the breadcrumb schema output nor will they alter WooCommerce's breadcrumb visual output.

Please consult the Yoast SEO schema documentation to change the breadcrumb schema. Please consult the WooCommerce breadcrumb documentation to change WooCommerce's breadcrumb output.

screenshot_519

@Apfelbiss
Copy link

Apfelbiss commented Apr 1, 2022

Hello,

thank you very much for these snippets.

But "$text_to_remove" does not work for text with an "&" in it.
I tried it with (all without blanks, of course):

  • &
  • & amp ;
  • & #x26 ;
  • & #38 ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment