Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Need to modify Yoast SEO breadcrumbs output WordPress

  • SOLVED

I'm trying to remove the link to the parent category in the breadcrumbs trail. The structure of the breadcrumbs is: HOME>>PARENT-CATEGORY>>CHILD-CATEGORY>>...
There is a filter available for this: "wp_seo_get_bc_ancestors" (Allows changing the ancestors for the current page in the breadcrumb).

Answers (3)

2017-04-24

Reigel Gallarde answers:

can you please try this:

I've pasted the code on pastebin.com for readable format.
https://pastebin.com/jvzALZQe

copy the code and paste it on functions.php of your theme.


jrcollins comments:

Hi Reigel, I tried the code but there seems to be a problem. The links have been removed from both the parent and child categories but the label is still visible.
You can see what I mean here: http://urlgone.com/14d985/


Reigel Gallarde comments:

But isn't it that the child has always been no link? even without my code.


jrcollins comments:

It depends which page you are viewing. Anyway, all I want to do is remove the parent category from all pages.


Reigel Gallarde comments:

Sorry, I'm quite lost.

the code will only check if it's a category, then if it is a parent, it will remove the link.

do you want to remove the link only or also remove it's text and not just link?


if you want to remove the link entirely, including the text, you need to modify the for loop in the code given... like this

for ( $i = 1; $i < sizeof($crumbs)-1; $i++ ) {
if ( isset( $crumbs[$i]['term'] ) ) {
unset($crumbs[$i]);
}
}


jrcollins comments:

I want to remove both the link and the text.


Reigel Gallarde comments:

Then this should do it. Same as I commented above.

new code can be found here: https://pastebin.com/eCVZCctf


jrcollins comments:

Getting closer,, just need to add the link for the child category.


Reigel Gallarde comments:

hmm... try this...

above return $crumbs;, add $crumbs[] = array();

should be something like below:

$crumbs[] = array(); // just add this line.
return $crumbs;


jrcollins comments:

Sorry, I made a mistake in my functions file and crashed the site but I have it back up again now. The code is now working too. Thanks for your help.

2017-04-24

Francisco Javier Carazo Gil answers:

Good morning,

Try with it: https://pastebin.com/8LfFdX6S

2017-04-24

Hai Bui answers:

Please copy this into functions.php of the theme

add_filter('wpseo_breadcrumb_links', 'filter_wpseo_breadcrumb_links');
function filter_wpseo_breadcrumb_links( $crumbs ){
foreach ($crumbs as $key => $crumb) {
if ( $crumb['term'] && $crumb['term']->parent == 0 ) {
unset($crumbs[$key]);
}
}
return $crumbs;
}