Skip to content

Instantly share code, notes, and snippets.

@paulvanbuuren
Last active September 3, 2018 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulvanbuuren/266d2bc439f04bc93aa7fe8a0330db30 to your computer and use it in GitHub Desktop.
Save paulvanbuuren/266d2bc439f04bc93aa7fe8a0330db30 to your computer and use it in GitHub Desktop.
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