Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.