Created
June 22, 2012 11:22
-
-
Save Mamaduka/2972170 to your computer and use it in GitHub Desktop.
Featured image Open Graph meta tag
This file contains hidden or 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 | |
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