Skip to content

Instantly share code, notes, and snippets.

@schemapress
Last active November 25, 2018 00:01
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 schemapress/62b9a03b4e7892e11122578241b26450 to your computer and use it in GitHub Desktop.
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/
<?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