Created
February 2, 2017 14:23
-
-
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
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
// ...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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!