Fix Open Graph Images Blocked by robots.txt
In this article
When social platforms like Facebook, X, or LinkedIn fetch a page to generate a link preview, they first check your site's robots.txt file. If that file blocks the crawler from accessing the Open Graph image URL, the preview will show a blank or broken image. This guide walks you through finding the block, fixing it, and verifying the preview works again.
What You'll Need
- Access to your website's file manager or FTP/SFTP client (to edit
robots.txt) - The exact URL of the Open Graph image (usually found in your page's HTML source)
- A browser with developer tools (Chrome, Firefox, Edge, or Safari)
- Optional: a URL inspection tool like Google Search Console (if your site is registered)
Step-by-Step
- Find the Open Graph image URL. Open the page that's showing the broken preview. Right-click the page and select "View Page Source" (or press Ctrl+U on Windows / Cmd+U on Mac). Search for
og:image. The content attribute will contain the full URL of the image. Copy it exactly. - Check if the image URL is blocked by robots.txt. Open a new browser tab and go to
https://www.yourdomain.com/robots.txt. Look for anyDisallowrules that match the image path. For example, if your image is at/images/og/default.jpgand robots.txt hasDisallow: /images/, that's the problem. - Test the image URL with a crawler simulator. Use a tool like Google's Rich Results Test or the Facebook Sharing Debugger. Paste the image URL into the test tool. If it says "Blocked by robots.txt" or "URL blocked", you've confirmed the issue.
- Edit robots.txt to allow the image. Open your site's
robots.txtfile via your file manager or FTP. Add a specificAllowrule for the image path, placed before the broaderDisallowrule. For example: - Save and upload the file. Save the changes and upload the file if you're using FTP. If you're using a CMS like WordPress, you might edit it via the theme editor or a plugin like Yoast SEO.
- Clear caches. Social platforms cache the preview. After fixing robots.txt, use the platform's debugger tool to force a re-fetch. For Facebook, go to the Sharing Debugger, paste your page URL, and click "Scrape Again". For X (Twitter), use the Card Validator. For LinkedIn, use the Post Inspector.
- Verify the fix. After re-fetching, the debugger should show the correct image. If not, wait a few minutes and try again. Also test the image URL directly in a browser to ensure it loads without a 403 or 404 error.
User-agent: * Allow: /images/og/default.jpg Disallow: /images/
Common Mistakes
- Blocking the entire image directory. A
Disallow: /images/rule blocks all images, including your OG image. Always use a specificAllowrule for the exact image path. - Using a relative URL in the
og:imagetag. Theog:imagecontent must be an absolute URL (starting withhttps://). A relative path like/images/og.jpgwon't work. - Forgetting the
og:image:widthandog:image:heighttags. Some platforms require these to render the preview correctly. Add them if you haven't already. - Editing the wrong robots.txt. If you have a staging site or a CDN, make sure you're editing the live production robots.txt.
- Not clearing the platform's cache. Even after fixing robots.txt, the old broken preview may persist until you use the debugger to re-fetch.
Tips
- Always place
Allowrules beforeDisallowrules in robots.txt. The first matching rule wins for most crawlers. - Use a dedicated folder for OG images, like
/og-images/, and never block that folder in robots.txt. - Keep your OG image under 8MB and in a widely supported format like JPG or PNG. Very large images may be ignored.
- Test your robots.txt with Google's Robots Testing Tool (now part of Search Console) to see which URLs are blocked.
- If you use a CDN or a security plugin, check that it isn't adding its own robots.txt rules or blocking image requests from social crawlers.
Troubleshooting
If the preview still shows a broken image after fixing robots.txt, try these steps:
- Check for other blocks. Some sites use
X-Robots-TagHTTP headers. Open the image URL in a browser's developer tools (Network tab) and look for aX-Robots-Tagheader. If it saysnoindexornofollow, that can also block crawlers. - Verify the image is publicly accessible. Open the image URL in an incognito window. If you get a 403, the server may require authentication or block certain user agents. Check your server's access logs for the social platform's crawler.
- Check for a CDN cache. If you use Cloudflare or similar, the old robots.txt might be cached. Purge the cache for the robots.txt file and the image URL.
- Test with a different platform. If Facebook works but X doesn't, the issue might be specific to that platform's crawler. Check their documentation for any additional requirements.
- Look at the page's HTML. Ensure the
og:imagetag is in the<head>section, not in the body. Also, check for duplicateog:imagetags – the first one is usually used.
Frequently Asked Questions
Why does robots.txt affect Open Graph images?
Social platforms use their own crawlers to fetch your page and its metadata. If robots.txt disallows the image path, the crawler cannot download the image, so it can't show it in the preview.
Can I block all images except the OG image?
Yes. Use a specific Allow rule for the exact image URL before the Disallow rule for the directory. For example: Allow: /images/og.jpg then Disallow: /images/.
How long does it take for the preview to update after fixing robots.txt?
It depends on the platform. Facebook's debugger refreshes immediately when you click "Scrape Again". X and LinkedIn may take a few minutes to a few hours. Always use the platform's debugger to force an update.
What if I don't have access to robots.txt?
If you're on a shared hosting or a CMS like WordPress, you can often create a robots.txt file via the file manager or a plugin. If you don't have file access, contact your hosting provider or web developer.
Does the size of the OG image matter?
Yes. Most platforms recommend a minimum of 1200x630 pixels and a maximum file size of 8MB. Very large or very small images may be ignored or stretched.
Can I use a different image for each page?
Absolutely. Just ensure each page has its own og:image tag pointing to a unique URL that is not blocked by robots.txt.