Last active
August 29, 2015 14:14
-
-
Save steezeburger/231b3982e78fb4080609 to your computer and use it in GitHub Desktop.
This sets a pages og:image property to the 'featured image' of that page. Facebook uses og:image when displaying images for posts to Facebook.
This file contains 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
<?php | |
// 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; | |
// Use featured image if available | |
if (has_post_thumbnail( $post->ID )) { | |
$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] ) . '"/>'; | |
} | |
} // insert_db_in_head() | |
// Add function to wp_head hook | |
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