Last active
November 25, 2018 00:01
-
-
Save schemapress/62b9a03b4e7892e11122578241b26450 to your computer and use it in GitHub Desktop.
Use Yoast SEO Title and Description in Schema Output https://schema.press/docs/yoast-seo-title-description/
This file contains hidden or 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 //* do not include php tag | |
add_filter( 'schema_output', 'schema_wp_override_description_yoast_seo_5636346455' ); | |
add_filter( 'schema_about_page_output', 'schema_wp_override_description_yoast_seo_5636346455' ); | |
add_filter( 'schema_contact_page_output', 'schema_wp_override_description_yoast_seo_5636346455' ); | |
/* | |
* Pull Schema Title and Description values from Yoast SEO | |
*/ | |
function schema_wp_override_description_yoast_seo_5636346455( $schema_output ) { | |
// get Title (Headline) value from Yoast SEO post meta | |
$headline = get_post_meta( get_the_ID(), '_yoast_wpseo_title', true); | |
// get Description value from Yoast SEO post meta | |
$desc = get_post_meta( get_the_ID(), '_yoast_wpseo_metadesc', true); | |
// override the values in schema output | |
$schema_output["headline"] = $headline; | |
$schema_output["description"] = $desc; | |
// return our schema array | |
return $schema_output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment