Skip to content

Instantly share code, notes, and snippets.

@dannymichel
Created November 22, 2012 22:51
Show Gist options
  • Save dannymichel/4133215 to your computer and use it in GitHub Desktop.
Save dannymichel/4133215 to your computer and use it in GitHub Desktop.
OpenGraph wp_head
add_action('wp_head', 'opengraph_on_single');
function opengraph_on_single() {
if ( is_single() ) {
global $post;
setup_postdata( $post );
echo '<meta property="og:type" content="article" />
<meta property="og:title" content="' . esc_attr( get_the_title() ) . '" />
<meta property="og:url" content="' . get_permalink() . '" />
<meta property="og:description" content="' . esc_attr( get_the_excerpt() ) . '" />';
if ( has_post_thumbnail() ) {
$imgsrc = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . $imgsrc[0] . '" />'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment