Skip to content

Instantly share code, notes, and snippets.

@Mamaduka
Created June 22, 2012 11:22
Show Gist options
  • Save Mamaduka/2972170 to your computer and use it in GitHub Desktop.
Save Mamaduka/2972170 to your computer and use it in GitHub Desktop.
Featured image Open Graph meta tag
<?php
function canvas_featured_open_graph_meta() {
if ( is_single() || is_page() ) {
global $post;
if ( has_post_thumbnail( $post->ID ) )
$thumbnail_id = get_post_thumbnail_id( $post->ID );
if ( ! empty( $thumbnail_id ) ) {
$thumbnail_src = wp_get_attachment_image_src( $thumbnail_id );
echo '<meta property="og:image" content="' . esc_url( $thumbnail_src[0] ) . '" />';
}
}
}
add_action( 'wp_head', 'canvas_featured_open_graph_meta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment