How to make Facebook choose the right photo when sharing articles

You may encounter random images when sharing an article on Facebook. As you have to search the images that Facebook shows you from your site next to the snippet for the correct prominent image for the article, and the problem is that you do this over and over again. The important thing is, after I did a simple search for a solution, I found a simple way that you can do with ease, and it is important, even if someone else would like to participate, he will not sit around looking for the correct image of the article. The important thing is to get to the heart of the topic

It depends on the following terms:

<link rel=”image_src” href=”رابط الصورة” />
<meta property=”og:image” content=”رابط الصورة” />

This code we will put in the header, but it needs some modification so that it works automatically with WordPress, but in order for it to work without problems, the template must support prominent images

We open the header.php file and before the </head> tag, we paste the following code:

2if (is_single()) :
3if (has_post_thumbnail()) :
4$img = wp_get_attachment_image_src( get_post_thumbnail_id($postid), “full” );
5$url = $img[‘0’];
6echo ‘<link rel=”image_src” href=”‘.$url.'” />’;
7echo ‘<meta property=”og:image” content=”‘.$url.'” />’;

In this case the code uses the highlighted image that you specified when writing a post. Save the file and try sharing a post to see the result

Illustrative image

This image shows that no more than one prominent image was chosen, unlike what we were in the past. You will notice that Facebook searches for all the images on your site and then makes you choose the appropriate image


Other ways to choose the right Facebook photo

Check out the new posts I’ve written recently regarding getting Facebook to pick the right photos

  1. Force Facebook to use the featured image automatically – using a hack
  2. Solve the problem of images when sharing on Facebook – using add-ons

end of transmitter

I hope that you benefit from this method, as it is important for your visitors and for you as well.

Peace, mercy and blessings of God

Leave a Comment