Show Yoast Breadcrumbs Above Post Content
Prints the Yoast SEO breadcrumb trail at the top of posts and pages for themes that have no breadcrumb spot of their own.
Opens WPIDE on
Code
// Post types that get the breadcrumbs.
$wpide_crumb_types = array( 'post', 'page' );
add_filter( 'the_content', function ( $content ) use ( $wpide_crumb_types ) {
if ( ! function_exists( 'yoast_breadcrumb' ) || is_front_page() || ! is_singular( $wpide_crumb_types ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$trail = yoast_breadcrumb( '<div class="wpide-breadcrumbs">', '</div>', false );
return $trail ? $trail . $content : $content;
}, 5 );
Notes
Turn on breadcrumbs under Yoast SEO > Settings > Advanced > Breadcrumbs. Skip this snippet if your theme already shows them.
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.