Use Yoast SEO meta title in site search

For more information, see Yoast SEO title and description in site search results.

$title = '';
if( is_search() && function_exists( 'wpseo_replace_vars' ) ) {
	global $post;
	$title = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true );
	$title = wpseo_replace_vars( $title, $post );
if( empty( $title ) ) {
	$title = get_the_title();

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk