Skip to content

Instantly share code, notes, and snippets.

@laurenproctor
Last active August 29, 2015 14:05
Show Gist options
  • Save laurenproctor/e7c19fcffdb0d0225712 to your computer and use it in GitHub Desktop.
Save laurenproctor/e7c19fcffdb0d0225712 to your computer and use it in GitHub Desktop.
//Adding the Open Graph in the language attributes
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
//Adding Open Graph Meta Info
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo '<meta property="fb:admins" content="172503922814423"/>'; // fb user id
echo '<meta property="og:title" content="' . get_the_title() . '"/>';
echo '<meta property="og:type" content="website"/>';
echo '<meta property="og:url" content="' . get_permalink() . '"/>';
echo '<meta property="og:site_name" content="Mag+"/>';
if(!has_post_thumbnail( $post->ID )) { //if the post does not have featured img, use default logo img
$default_image="http://www.magplus.com/wp-content/themes/magplus_2/images/og-image-logo-blk.png";
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment