Skip to content

Instantly share code, notes, and snippets.

@wpexplorer
Created September 18, 2013 18:25
Show Gist options
  • Save wpexplorer/6613334 to your computer and use it in GitHub Desktop.
Save wpexplorer/6613334 to your computer and use it in GitHub Desktop.
Open Graph Video URL For Facebook - WordPress Function
<?php
// Add video open graph metatag
add_action( 'wp_head', 'wpex_fb_video_opengraph');
function wpex_fb_video_opengraph() {
if ( is_singular( 'post' ) ) {
global $post;
$output='';
$postid = $post->ID;
$format = get_post_format( $post_id );
if ( $format !== 'video' ) return; // not video post format, so exit
$video = get_post_meta( $postid, 'wpex_post_oembed', true );
if ( $video !== '' ) {
$output = '<meta property="og:url" content="'. $video .'" />';
}
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment