...

WordPress: How to Fix No featured thumbnail issue on facebook share


Yesterday I’ve noticed that when I share my post to my Facebook Fanpage, my feature image was not showing, I’ll try to find answers by searching Google but I couldn’t find the perfect solution to fix the problem, and I’m sure if you are reading my post you are also on my situation before.


I’ve searched google for keywords that Facebook debugger giving like improper use of OG image meta tags, but it always shows results with the same problem and no solution.

For almost 2 to 3 hours yesterday I’ve been searching for a solution, I follow some instructions that I read in some forum that I found while searching for answers, like removing all the plugins related to Facebook and activate it one by one to find out what plugins causing the conflict but I  couldn’t make it to work. But I found a perfect solution to my problem that I think it might also solve yours, I decided to write this post to share and help.

This post will show the simple steps that you are looking to fix no featured thumbnail issue on Facebook share, I’ve got the solution from wpbeginner.com and I’m thankful for them for making that simple yet perfect solution to the problem.


Follow this simple step to fix your no featured thumbnail problem, by the way this solution is for WordPress users only.

Open up your functions.php file and paste the code inside the php tags, be sure to put the code inside the closing of php tag or else you know the results.

function insert_image_src_rel_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$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 "
";
}
add_action( 'wp_head', 'insert_image_src_rel_in_head', 5 );

Please consider sharing if you find it helpful, credits to wpbeginner.com 🙂

Leave a Comment