Use Your Post Featured Image In Facebook Share Automatically

By -
when sharing on facebook or even pressing the "like" button,
your featured image of the post will show as the default image.
if no featured image you can tell the function to use your LOGO.
just paste this code in functions.php, don't forget to tell
the function where your logo is (SOURCE_TO_YOUR_LOGO).
function insert_image_src_rel_in_head() {
 global $post;

 if ( !is_singular()) //if it is not a post or a page do nothing

 if(!has_post_thumbnail( $post->ID )) {
 echo '<meta property="og:image" content="' . $default_image . '"/>';
 $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 "\n";
add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );

WordPress is a full featured Content Management System (CMS). It has incorporated a rich suite of capabilities that have proven to be extremely popular because it allows anyone to create vibrant, dynamic sites without any programming knowledge. Its large range of features, coupled with a clean and easy-to-understand interface make it a fan fave among website novices; 27% of all the websites in existence and 20% of all new ones use this amazing platform.

2 Comments to Use Your Post Featured Image In Facebook Share Automatically

Leave a Reply

Your email address will not be published. Required fields are marked *

Human test: *