Skip to content

Instantly share code, notes, and snippets.

@fredrikln
Created February 2, 2017 14:23
Show Gist options
  • Save fredrikln/abe74069b28a9f3adde0730fe949e73c to your computer and use it in GitHub Desktop.
Save fredrikln/abe74069b28a9f3adde0730fe949e73c to your computer and use it in GitHub Desktop.
Change Yoast SEO og:type to video and add og:video meta tag for custom post type
// ...snip
// Change Yoast og:type and add og:video meta tags for a custom post type in WordPress
// Note: This assumes you are using a custom field named 'youtube_id' using Advanced Custom Fields plugin
// Change og:type of episodes and videos to video
function yoast_change_opengraph_type( $type ) {
// If this is the wanted custom post type
if ( get_post_type() == 'episode' ) {
return 'video';
}
}
add_filter( 'wpseo_opengraph_type', 'yoast_change_opengraph_type', 10, 1 );
// Add og:video meta tag for episodes and videos
function yoast_add_og_video( ) {
// If this is the wanted custom post type
if ( get_post_type() == 'episode' ) {
// Echo the og:video meta tag
echo sprintf("<meta property=\"og:video\" content=\"https://www.youtube.com/v/%s\">\n", get_field('youtube_id'));
}
}
add_action( 'wpseo_opengraph', 'yoast_add_og_video', 10, 0 );
// ...snip
@ofyalcin
Copy link

Thank you!

@jsumabong
Copy link

Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment