Yoast SEO breadcrumbs. How to add and edit them in your theme.

In this article we will show how to add breadcrumbs using Yoast SEO. Additionally adding custom breadcrumb links.

How to add breadcrumbs

To add breadcrumb we need to call yoast_breadcrumb( ) function. This function accept three parameters:

  • $before – String which will be shown before breadcrumb. For example if you want to wrap all links of breadcrumb into one element, you should provide start tag here.
  • $after – String which will be shown after breadcrumb. For example if you have provided any start tag in previous parameter here, you should add end tag.
  • $display – Boolean which determine to show or hide breadcrumb. Default is true.

Official plugin documentation suggest adding this code in places where you want to display breadcrumbs.

if ( function_exists('yoast_breadcrumb') ) {
  yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}

In addition, do not forget to enable breadcrumbs in SEO settings. By default, they disabled.

How to edit breadcrumbs

General settings

General settings of breadcrumbs displayed under “Breadcrumbs” tab in “Search Appearance” subpage of “SEO” in your admin panel. Url path should be /wp-admin/admin.php?page=wpseo_titles#top#breadcrumbs.

Custom breadcrumb links

In some specific situations, we would like to show one or few additional links in custom breadcrumb. For this purpose, we will use wpseo_breadcrumb_links filter. This filter provide array of breadcrumb links. For instance, we can loop to change current settings like url, text or add new link. In addition to add custom breadcrumb links we need to modify provided array and return it with new items.

Example below shows how to add custom link to begin of breadcrumb.

add_filter( 'wpseo_breadcrumb_links', 'my_custom_breadcrumb_links' );
function my_custom_breadcrumb_links( $links ) {

    $breadcrumbs[] = array(
        'url' => home_url('/custom-page'),
        'text' => 'My custom page',
    );

    array_splice( $links, 0, 0, $breadcrumbs ); //Prepend array to begin

    return $links;
}