Add the Blog Page to Yoast Breadcrumbs on Posts
Inserts your blog page (Settings > Reading > Posts page) after "Home" in the Yoast SEO breadcrumbs of single posts and post archives.
Opens WPIDE on
Code
add_filter( 'wpseo_breadcrumb_links', function ( $links ) {
$blog_id = (int) get_option( 'page_for_posts' );
if ( ! $blog_id || ! is_array( $links ) || ! ( is_singular( 'post' ) || is_category() || is_tag() || is_date() ) ) {
return $links;
}
foreach ( $links as $link ) {
if ( isset( $link['id'] ) && (int) $link['id'] === $blog_id ) {
return $links;
}
}
array_splice( $links, 1, 0, array( array( 'url' => get_permalink( $blog_id ), 'text' => get_the_title( $blog_id ), 'id' => $blog_id ) ) );
return $links;
} );
Notes
Does nothing when no posts page is set or Yoast already shows it.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.