How to Display Correct Post Thumbnail on WordPress blogs, When Sharing links to Facebook?

This post related to one issue I faced yesterday on my blog. The issue looks simple, whenever I tried to share my blog post link to Facebook it not showing the correct Post Thumbnail. I think this issue happened to my blog when I switched to one premium WordPress theme from theme-junkie.

As you know normally we go for official support for similar issues, Me too first go for the theme support page and  I asked this question with theme provider but unfortunately they are telling they have no idea about this issue. But anyhow! My issue has been fixed now check out how we fixed the issue.

Facebook-Share

Step 1  : Open the  Header.Php on your WordPress Theme.

Step 2 : Search for php wp_head(); ?>

Step 3 : Copy below code and paste it above php wp_head(); ?>

[php]
<!–?php global $wp_query; $thePostID = $wp_query—>post->ID;
if( has_post_thumbnail( $thePostID )){
$thumb_id = get_post_thumbnail_id( $thePostID );
$image = wp_get_attachment_image_src( $thumb_id );
echo ”;
} ?>
[/php]

Step4: Save you Header.php file and that’s it! You are done.

Please do any changes to your WordPress theme if you know what you are doing. We’re not responsible in anyway whatsoever if you mess it up.


									
2 Comments

Add a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.