Last active
September 3, 2018 13:04
-
-
Save paulvanbuuren/266d2bc439f04bc93aa7fe8a0330db30 to your computer and use it in GitHub Desktop.
Use and filter Yoast page title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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