Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use and filter Yoast page title
<?php
//========================================================================================================
// add a filter for Genesis framework post titles
add_filter( 'genesis_post_title_text', 'wbvb_example_use_seo_title', 15 );
/**
* If a Yoast SEO title is found for a post, return this title after parsing it
*
* @return string with a title
*/
function wbvb_example_use_seo_title( $title ) {
global $post;
if ( function_exists( 'wpseo_replace_vars' ) ) {
// if there is an alternative SEO title
$yoasttitle = get_post_meta( $postid , '_yoast_wpseo_title', true);
if ( $yoasttitle ) {
// return it after we made sure all placeholders are parsed
$title = wpseo_replace_vars( $yoasttitle, $post );
}
}
// there you have your page title
return $title;
}
//========================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.