Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove link from the Yoast SEO breadcrumbs site wide
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/*
* Remove the last breadcrumb, the post name, from the Yoast SEO breadcrumbs
* 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;
}
@dustinleer

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.