Yoast SEO breadcrumb filters – wpseo_breadcrumb_links and more

In this guide, we will talk about Yoast SEO breadcrumb filters and learn how these filters are used with examples. The main filter we will be checking will be the wpseo_breadcrumb_links. We’ll also talk about other filters like wpseo_breadcrumb_single_link, wpseo_breadcrumb_output, wpseo_breadcrumb_indexables, etc, but wpseo_breadcrumb_links will be the focus of our tutorial.

Yoast SEO breadcrumb filters - wpseo_breadcrumb_links and more

Breadcrumbs are a very important part of SEO and website optimization in general. The Yoast plugin offers a breadcrumb feature, and if you want to improve your website’s SEO, it’s best if you use it. Now let’s get started and check the wpseo_breadcrumb filters one by one.

Table of contents

Let’s start with the wpseo_breadcrumb_links filter. This is one of the most used breadcrumb filters on this list. Developers often use this filter because it allows them to change links or link elements in the breadcrumbs of the Yoast plugin. More specifically, this filter allows them to change the order of links, texts, remove or add an element, etc.

Let’s look at an example of how you can use this filter.

add_filter( 'wpseo_breadcrumb_links', 'wp_guide_wpseo_breadcrumb_links_filter' );

/**
 * @param array $crumbs The crumbs array.
 */
function wp_guide_wpseo_breadcrumb_links_filter( $crumbs ){

	return $crumbs;
}

As you may have guessed $crumbs is an array.

Here is an example of an array with data about links in the order of output to the screen.

Array
(
	[0] => Array
		(
			[url] => https://example.com/category/country/
			[text] => Country
			[term_id] => 42
			[taxonomy] => category
		)

	[1] => Array
		(
			[url] => https://example.com/category/country/usa/
			[text] => USA
			[term_id] => 456
			[taxonomy] => category
		)

	[2] => Array
		(
			[url] => https://example.com/country/usa/washington/
			[text] => Washington
			[id] => 2288
		)

)

wpseo_breadcrumb_links is used in two Yoast plugin files (class-admin-init.php and Breadcrumbs-generator.php). You can find these files in the following paths – wordpress-seo\admin\class-admin-init.php and wordpress-seo\src\generators\breadcrumbs-generator.php.

In the first file, you can find the code for this filter on line 278. It occurs only once.

'alternative' => 'wpseo_breadcrumb_links',

In the second file, you can find the code for this filter on lines 193, 197, 202, and 203. It occurs four times.

193

* Filter: 'wpseo_breadcrumb_links' - Allow the developer to filter the Yoast SEO breadcrumb links, add to them, change order, etc.

197

$filtered_crumbs = \apply_filters( 'wpseo_breadcrumb_links', $crumbs );

202

'Filter: \'wpseo_breadcrumb_links\'',

203

'The `wpseo_breadcrumb_links` filter should return a multi-dimensional array.',

The next filter in the list of Yoast SEO breadcrumb filters is wpseo_breadcrumb_single_link. This filter allows changing of each link being put out by the plugin breadcrumbs class. Here is an example of using this filter.

add_filter( 'wpseo_breadcrumb_single_link', 'wp_guide_wpseo_breadcrumb_single_link_filter', 15, 5 );

function wp_guide_wpseo_breadcrumb_single_link_filter( $link_output, $link ){

	// filter...
	return $link_output;
}

Where $link_output is a string and $link is an array.

This filter is used in the breadcrumb-presenter.php file. You can find this file in the following path: wordpress-seo\src\presenters\breadcrumbs-presenter.php. You can find the code for this filter on lines 159 and 165.

159

Filter: 'wpseo_breadcrumb_single_link' - Allow changing of each link being put out by the Yoast SEO breadcrumbs class.

165

return \apply_filters( 'wpseo_breadcrumb_single_link', $link, $breadcrumb );

The next filter allows filtering the plugin’s breadcrumb link information. Developers rarely use this filter and it is only found in this file – wordpress-seo\src\generators\breadcrumbs-generator.php.

Line 213

* Filter: 'wpseo_breadcrumb_single_link_info' - Allow developers to filter the Yoast SEO Breadcrumb link information.

Line 220

return \apply_filters( 'wpseo_breadcrumb_single_link_info', $link_info, $index, $crumbs );

wpseo_breadcrumb_separator

This filter allows changing the plugin breadcrumb separator. This filter occurs once in the Yoast SEO plugin files and is located in this file – wordpress-seo\src\presenters\breadcrumbs-presenter.php.

Line 242

$this->separator = \apply_filters( 'wpseo_breadcrumb_separator', $this->helpers->options->get( 'breadcrumbs-sep' ) );

wpseo_breadcrumb_output

wpseo_breadcrumb_output allows you to change the HTML output of the breadcrumb class. Developers commonly use this filter to change the output of this plugin’s breadcrumb class, and it’s one of the popular filters on our list. You can check an example of using this filter below.

add_filter( 'wpseo_breadcrumb_output', 'wp_guide_wpseo_breadcrumb_output_filter', 13, 5 );

function wp_guide_wpseo_breadcrumb_output_filter( $output, $presentation ){
	// filter...
	return $output;
}

Where $output is a string and HTML output at the same time, and $presentation is an Indexable_Presentation. In Yoast SEO files, this filter occurs 2 times (on lines 102 and 108) in this file – wordpress-seo\src\presenters\breadcrumbs-presenter.php.

wpseo_breadcrumb_indexables

And the last and rarely used filter is wpseo_breadcrumb_indexables. Created for WooCommerce. This filter is found in two Yoast SEO plugin files (breadcrumbs-generator.php and woocommerce.php). You can find these files in the following paths: wordpress-seo\src\generators\breadcrumbs-generator.php and wordpress-seo\src\integrations\first-party\woocommerce.php.

In breadcrumbs-generator.php you can find this filter on line 148.

$indexables = \apply_filters( 'wpseo_breadcrumb_indexables', $indexables, $context );

In woocommerce.php you can find this filter on line 108.

\add_filter( 'wpseo_breadcrumb_indexables', [ $this, 'add_shop_to_breadcrumbs' ] );

If you want to learn more about Yoast SEO breadcrumbs, you can check out their website and see how to implement breadcrumbs in general – more info from the plugin author.

A little about the Yoast SEO plugin

The Yoast SEO plugin is one of the most popular and useful plugins available on the WordPress.org directory. It is no coincidence that this plugin has over 5 million active users and an average WordPress rating of 4.8 (almost 5 out of 5). This plugin has a lot of useful features, so it’s better to try it once than hear it several times πŸ™‚ By the way, if you use this plugin and you are interested in other Yoast SEO filters besides breadcrumbs, then there is another important filter that you should know about, it is called wpseo_json_ld_search_url.

If you have been using another plugin for a while and everything suits you, then you have already made your choice, there is nothing to add.

By the way, if you want to watch a video tutorial on how to add Yoast breadcrumbs using Gutenberg blocks, then below is a video tutorial from Yoast on YouTube.

In addition, you can check the screenshot below and see how to add Yoast breadcrumbs using Gutenberg blocks.

Adding Yoast SEO Breadcrumbs with the Gutenberg Block

Conclusion

Now let’s check what we’ve learned from this tutorial about Yoast SEO breadcrumb filters and draw some conclusions. If we conclude, we can note that wpseo_breadcrumb_links is one of the most popular and frequently used filters among developers. By the way, it should be mentioned that there are 4 more breadcrumbs (which are rarely used) that we have not covered: wpseo_breadcrumb_output_id, wpseo_breadcrumb_output_class, wpseo_breadcrumb_output_wrapper, and wpseo_breadcrumb_single_link_wrapper.

By using this plugin’s filters, you can make some changes to the default code and improve your site’s SEO. Some users don’t scroll up (or even down) to navigate a website through menus, so in this case, breadcrumbs are another type of menu. In any case, if you want to improve and increase your website traffic, then adding breadcrumbs is a good way to both increase it and help your users navigate and understand the structure of your website.

It’s up to you to add breadcrumbs or not, but user experience and other arguments suggest that it’s a necessary element of the site.