8

Remove Element From the Yoast SEO Breadcrumbs

 3 years ago
source link: https://pineco.de/snippets/remove-element-from-the-yoast-seo-breadcrumbs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Remove Element From the Yoast SEO Breadcrumbs

With Yoast SEO, we can use an excellent and straightforward helper function for creating breadcrumbs (yoast_breadcrumb()).

Under the Search Appearance -> Breadcrumbs menu, we can customize it too. Besides this, there can be use cases where you want to remove something from the generated list of links (like a page of the custom post type archive); you can do it like so:


/**
 * Remove "Positions" from breadcrumbs
 */
function pine_remove_yoast_breadcrumb_link($link_output , $link)
{
    $text_to_remove = 'Positions';

    if($link['text'] == $text_to_remove) {
      $link_output = '';
    }

    return $link_output;
}
add_filter('wpseo_breadcrumb_single_link' ,'pine_remove_yoast_breadcrumb_link', 10 ,2);

Inside the $link attribute, we can access the url, text, and ID of the link. The $link_output contains the whole displayed link; if we want to delete a link, we have to set this to empty.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK