Skip to content

Instantly share code, notes, and snippets.

@chillybin
Created November 16, 2015 03:57
Show Gist options
  • Save chillybin/8b26d51a758bfac60cf7 to your computer and use it in GitHub Desktop.
Save chillybin/8b26d51a758bfac60cf7 to your computer and use it in GitHub Desktop.
For this example to work you will need to install Advanced Custom Fields, create a text field called "youtube_video_id" and then when you are creating your post, you can embed your video, and then use the ID from YouTube into the text box.
add_action('wp_head', 'chillybin_custom_og_image');
function chillybin_custom_og_image() {
if (get_field('youtube_video_id')) { ?>
<meta property="og:image" content="http://img.youtube.com/vi/<? echo get_field('youtube_video_id'); ?>/mqdefault.jpg" />
<?php }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment