Fix: Facebook, Twitter, not fetching website’s images

Share with others

If Facebook, Twitter, or other social media are not fetching your images from website posts when you share them on these platforms, there may be some things you want to check at your end. Some of the reasons can be:

  1. Conflicts between themes or plugins
  2. Missing or corrupt image files
  3. Wrong file paths
  4. Incorrect file permissions (.htaaccess)
  5. Protected files or hotlink prevention (.htaaccess)

But before discussing further, first things first. If you haven’t already, make sure that OpenGraph is set properly on your website. This can be done using Yoast SEO RankMath or any other SEO plugin you may have.

You can also use social media tools to verify if the issue has been fixed by using Facebook Debugger and Twitter’s Social Card Validator.

Note: X (Twitter) has discontinued social card validator tool. Now, you can only validate links by just adding them to compose post from your Twitter account. If the image appears, it means it’s working fine.

Once done, one by one check the above-mentioned reasons.

  1. Make sure your plugins and themes aren’t causing this. Unfortunately, the only way to know is to change the theme and disable plugins to verify.
  2. Sometimes, files uploaded get corrupted, causing issues with showing OpenGraph images on social platforms. Reuploading files after editing can help in this case.
  3. Missing wrong file paths in images can also appear them broken. Check if the link of images you’re using are correct or not.
  4. Incorrect file permissions and protected files issue can also be the reason. Especially if you’ve a security plugin or a cache plugin that’s handling your .htaacess file. In my case, this was the issue. Let’s dive into it and how you can fix it easily.
  5. For hotlink prevention, you need to either turn off the feature from hosting or from the third party plugin you’re using. Or check your .htaacess file incase there’s a code sitting there that’s causing the block.

Fixing social card appearance issue for WordPress sites:

This can happen if you’ve used any plugin such as “All In One WP Security” aka AIOWP (in my case).

You can look into our guide to edit the .htaaccess file on your website to find and start editing .htaacess file of your particular website.

I’ll wait for you here till you learn from the above mentioned link to find and edit these files from your cPanel account.

Note: Before making any changes to your .htaaccess file, make sure to download it and take a backup before proceeding.

Done already? Let’s discuss further.

Now, you need to find this line of code in the .htaaccess file:

RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

After looking for this line of code, you can replace this line with the given code:

RewriteCond %{HTTP_USER_AGENT} (googlebot|bingbot|yandexbot) [NC,OR]
RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit|Twitterbot|Pinterest|LinkedInBot) [NC]
RewriteRule .*.(jpg|jpeg|gif|png|bmp)$ - [L]

After replacing the line with the new code in green, save changes and wait till its complete.

Do not close the browser, just clear cache of your website and try to share link on Twitter or Facebook after doing this.

Voila, it works!

It took me several hours to find and fix this little issue that was a headace for a week or so. I decided to share with others so that if anyone else is facing the same problem, can take help from this quick guide.

This code in the .htaaccess file will enable crawling to the images for these mentioned social media crawlers and others, but will still block access to irrelevant bots. Previously, the red colored code disabled all crawlers, including social media crawlers from fetching images.

The new code in green whitelists social media crawlers and block other irrelevant ones in this case. This includes hotlink prevention feature which discourages crawlers from fetching images.

I hope it was helpful. Feel free to drop questions in the comments if any.

Share with others
Abdullah
Abdullah

Abdullah, AKA "abdugeek," is a computer scientist turned tech writer and certified Growth Hacker. He has a versatile entrepreneurial mindset and is well-versed in the digital world with passion for animals, particularly fish. Founder of multiple digital startups in technology sector, he's constantly pushing boundaries and seeking new opportunities. Follow him on social media or learn more about him on his website.

Articles: 29

Leave a Reply

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.