Sub topic 12
Common pitfalls and troubleshooting
This chapter assumes you can write the core Open Graph tags (og:title, og:type, og:image, og:url) and add Twitter/X card tags. You should also be comfortable reading HTTP status codes and running curl. Here you learn to find out why a preview is missing, wrong, or out of date. You also learn which mistakes cause most failures.
Debug in the order the crawler works
A preview fails at one of four stages. Check them in order, because a failure at an early stage hides every later problem.
- The crawler cannot fetch your page.
- The fetched HTML does not contain the tags.
- The tags are present but invalid or misleading.
- Everything is correct, but the platform shows a cached older version.
Pitfall 1: The crawler never sees your page
Social crawlers identify themselves with user agents such as facebookexternalhit, Twitterbot, LinkedInBot, and Slackbot. A page can work in your browser and still fail for them.
Common causes:
- A web application firewall or bot protection that returns 403 or a challenge page to unknown user agents.
- A login wall or staging password. Crawlers do not log in.
- A
robots.txtrule that disallows the crawler's user agent. - Geo-blocking or IP allow-lists that exclude the crawler's addresses.
- A long redirect chain, or a redirect loop, such as
httptohttpstowwwto a locale path. - A slow response. Crawlers give up after a short timeout, so a page that takes many seconds to render may fail.
Test with the same user agent and follow redirects:
url="https://example.com/cold-coffee"
for ua in "facebookexternalhit/1.1" "Twitterbot/1.0" "Slackbot-LinkExpanding 1.0"; do
echo "== $ua"
curl -sL -A "$ua" -o /dev/null -w "status=%{http_code} final=%{url_effective} time=%{time_total}s\n" "$url"
curl -sL -A "$ua" "$url" | grep -ioE '<meta[^>]*(og:|twitter:)[^>]*>'
doneIf the status differs between user agents, your server or CDN treats them differently. Fix that before touching any tags.
Pitfall 2: Tags are added by JavaScript
Most crawlers fetch HTML and do not run your JavaScript. A single-page app that sets document.title and inserts meta tags after load shows the crawler an empty shell. The curl output above is the ground truth. If your tags are not in that output, the crawler does not see them either, even though browser developer tools show them.
Fixes, from simplest to most involved:
- Render the head on the server for each route (server-side rendering).
- Pre-render or statically generate pages that are shared often.
- Serve a pre-rendered version to known crawler user agents. This works, but it is fragile, and the content must match what users see.
Pitfall 3: Wrong attribute or misplaced tags
Open Graph uses the property attribute. The name attribute is for standard metadata and for Twitter tags. Some crawlers tolerate name="og:title", but others ignore it.
<!-- Wrong: some crawlers ignore this -->
<meta name="og:title" content="How to Brew Cold Coffee">
<!-- Right -->
<meta property="og:title" content="How to Brew Cold Coffee">Placement also matters. The HTML parser closes <head> early when it meets an element that is only valid in <body>, such as a <div>, an <img>, or a stray <iframe> injected by a script or template. Every meta tag after that point ends up in the body. Browsers may not care, but a crawler that only reads the head will miss those tags. Put the Open Graph tags near the top of the head, right after <meta charset> and <title>. A tag-reading crawler will then reach them even if the rest of the head is malformed.
Other markup mistakes to look for:
- Duplicate tags. Two
og:titlevalues, often one from a CMS plugin and one from your template, leave the result up to the crawler. Pick one source. - Unescaped quotes in content. A title like
The "Best" Coffeeinsidecontent="..."ends the attribute early. Escape with", as the helper from the dynamic generation chapter does. - Smart quotes or non-UTF-8 text without
<meta charset="utf-8">near the top of the head, which produces garbled titles.
Pitfall 4: Relative or inconsistent URLs
Crawlers do not reliably resolve relative URLs for og:image and og:url. Use absolute URLs with a scheme and host.
<!-- Wrong -->
<meta property="og:image" content="/images/cold-coffee.jpg">
<!-- Right -->
<meta property="og:image" content="https://example.com/images/cold-coffee-1200x630.jpg">Watch for these URL problems:
og:urlshould be the canonical address of the page. If it differs from the URL that was shared, platforms may follow it and show the preview for the canonical page. A wrongog:urlthat points to the home page makes every article show the home page preview.- Mixed
httpandhttps. Anhttp://image URL on anhttps://page can fail on some platforms, and many sites redirecthttptohttps, which adds a hop. - Tracking parameters.
?utm_source=xmakes a distinct URL for caching purposes, so each variant gets its own cached preview. - Non-ASCII or unencoded characters, such as spaces, in image paths.
Pitfall 5: Image problems
Image failures are the most common reason for a text-only or blank preview.
| Symptom | Likely cause | Fix |
|---|---|---|
| No image at all | Image URL returns 403, 404, or a redirect to a login page | Request the image URL with a crawler user agent and check the status |
| No image at all | Hotlink protection blocks requests without your site as referrer | Allow requests with no referrer for the preview images |
| Image is tiny or cropped badly | Dimensions far from the roughly 1.91:1 ratio, such as 1200x630 | Export a 1200x630 version for sharing |
| Image missing on one platform | Unsupported format, such as SVG, or a file that is too large | Use JPEG or PNG, and keep the file well under a few megabytes |
| Old image still shows | Platform cache | Re-scrape, or publish the image under a new URL |
| Image appears only after a second share | The first fetch timed out | Make the image fast, and check CDN cold-start time |
Check the image the same way the crawler fetches it:
curl -sIL -A "facebookexternalhit/1.1" https://example.com/images/cold-coffee-1200x630.jpg \
| grep -iE '^(HTTP|content-type|content-length|location)'You want a final 200, a content-type that starts with image/, and a content-length of a sensible size. If the content type is text/html, your image URL is returning an error or login page.
If you set og:image:width and og:image:height, make them match the real file. Wrong values do not repair the image. They can only mislead the layout of the card before the image loads. Always include og:image:alt, so the preview is usable with a screen reader.
Pitfall 6: Stale previews
Platforms cache the result of a scrape, sometimes for days. Editing your tags does not change what is already stored. This is why "I fixed it and nothing changed" is so common.
Ways to refresh:
- Use the platform's own debugging tool to fetch the URL again. Facebook's Sharing Debugger has a re-scrape button, and LinkedIn's Post Inspector does the same. The tools change over time, so look for the current ones in each platform's documentation.
- Change the URL the preview is keyed on, for example by changing the image filename (
cold-coffee-v2.jpg). A new image URL is fetched fresh even when the page itself is cached. - Do not rely on a query string like
?v=2on the page URL. It can create a separate preview, but the old shared link keeps the old one.
Messaging apps often cache previews on the client or their own servers. You may need to wait, or to share a variant of the link. Fix the root cause on your server first, because re-scraping a page that still serves bad tags only caches the bad result again.
Pitfall 7: Twitter/X and type mistakes
- Twitter/X needs
twitter:cardbefore it shows a rich card. Without it, you may get a plain link even when every Open Graph tag is correct. - A
twitter:cardvalue that does not match the image shape gives a wrong layout.summary_large_imageexpects a wide image, andsummaryexpects a small square one. og:typeshould be a valid type such aswebsiteorarticle. Article properties likearticle:published_timeneedog:typeset toarticle, and the time must be a valid ISO 8601 date, as in2026-11-01T09:00:00Z.og:localeuses thelanguage_TERRITORYform, for exampleen_US. A value likeen-usis not what the protocol specifies.
Pitfall 8: Preview text shows the wrong thing
If the preview title or description is not what you wrote, the crawler may have fallen back to other data. Without og:title, it may use the <title>. Without og:description, it may use <meta name="description"> or text from the page. This fallback is a feature, but it surprises people when one tag is missing or invalid. Treat the four core tags plus the description as required, so you never depend on guesses.
An audit script
This script fetches a page with a crawler user agent and reports the problems covered above. It uses only the Python standard library.
import sys
import urllib.request
from collections import Counter
from html.parser import HTMLParser
from urllib.parse import urlparse
REQUIRED = ["og:title", "og:type", "og:image", "og:url"]
URL_PROPS = ["og:image", "og:url"]
class MetaCollector(HTMLParser):
def __init__(self):
super().__init__()
self.metas = []
def handle_starttag(self, tag, attrs):
if tag == "meta":
self.metas.append(dict(attrs))
def audit(url):
request = urllib.request.Request(url, headers={"User-Agent": "facebookexternalhit/1.1"})
with urllib.request.urlopen(request, timeout=10) as response:
html = response.read().decode("utf-8", errors="replace")
collector = MetaCollector()
collector.feed(html)
problems = []
values = {}
counts = Counter()
for attrs in collector.metas:
name_attr = attrs.get("name", "")
if name_attr.startswith("og:"):
problems.append(f'uses name="{name_attr}" instead of property')
prop = attrs.get("property", "")
if prop.startswith("og:") or prop.startswith("article:"):
counts[prop] += 1
values.setdefault(prop, attrs.get("content", ""))
for prop in REQUIRED:
if prop not in values or not values[prop].strip():
problems.append(f"missing or empty {prop}")
for prop in URL_PROPS:
value = values.get(prop, "")
parsed = urlparse(value)
if value and not (parsed.scheme in ("http", "https") and parsed.netloc):
problems.append(f"{prop} is not an absolute URL: {value}")
for prop, count in counts.items():
if count > 1 and prop not in ("og:image", "article:tag", "article:author"):
problems.append(f"{prop} appears {count} times")
return problems
if __name__ == "__main__":
target = sys.argv[1]
found = audit(target)
if found:
print("\n".join(found))
sys.exit(1)
print("No problems found")Run it with python audit_og.py https://example.com/cold-coffee. It exits with status 1 when it finds a problem, so you can add it to a deployment check. Like the crawler, it sees only the raw HTML, which makes it a good check for the JavaScript pitfall. It cannot check cache state or image content, so still check images with the curl command above.
Symptom checklist
| What you see | Check first |
|---|---|
| No preview card at all | Crawler status code, `robots.txt`, firewall rules |
| Card with only the URL as title | Tags missing from the raw HTML, or placed in the body |
| Wrong title or description | Duplicate tags, missing `og:title`, or stale cache |
| Text correct, no image | Image URL status and content type, relative `og:image` |
| Right on one platform, wrong on another | Missing `twitter:card`, platform-specific cache |
| Fixed but unchanged | Re-scrape in the platform debugger, or change the image URL |
Exercise
A teammate says the Open Graph tags are correct because they appear in the browser's Elements panel. The Facebook debugger still shows no preview. What single check proves or disproves their theory, and what does a failing result tell you?
Show answer
Run curl with a crawler user agent, for example curl -sL -A "facebookexternalhit/1.1" URL, and look for the og: tags in the output. If they are missing, the tags are added by JavaScript after load, which crawlers do not run, so you need to render them on the server.
Exercise
You replaced the image on https://example.com/cold-coffee but kept the file name cold-coffee-1200x630.jpg. Shares still show the old image even after you re-scrape. Name two ways to get the new image shown.
Show answer
Publish the new image under a different URL, such as cold-coffee-v2.jpg, and update og:image. Alternatively, check whether a CDN is still serving the old file and purge it, then re-scrape. The platform may be fetching the old image from your CDN rather than from its own cache.
Exercise
A page has <meta name="og:title" content="Cold Coffee"> and <meta property="og:image" content="/img/cc.jpg">. List the two defects.
Show answer
The title tag uses name instead of the property attribute, so some crawlers ignore it. The og:image value is a relative URL, so it should be an absolute URL such as https://example.com/img/cc.jpg.