SEO & AI search · Guide
How to Add Open Graph Tags in WordPress
Short answer
Add Open Graph tags in WordPress with an SEO plugin such as Yoast or Rank Math, which writes the tags for you. Yoast turns Open Graph on by default, and you can set a custom title, description, and image per post. You can also add the tags by hand in your theme, or set a default image for pages that have none.
Key takeaways
- Open Graph tags control the title, description, and image shown when a link is shared.
- Four tags are required on every page: og:title, og:type, og:image, and og:url.
- Yoast SEO turns Open Graph on by default, and Rank Math writes the same tags.
- Use a 1200 by 630 pixel image with full URLs for og:image and og:url.
- Two plugins writing Open Graph tags will clash, so keep only one switched on.
What are Open Graph tags?
Open Graph tags are meta tags in the head of a page that control how the page looks when someone shares its link.
When you paste a URL into Facebook, X, LinkedIn, Slack, or WhatsApp, the platform reads these tags and builds a preview card with a title, a description, and an image. Without them, the platform guesses from the page text, and the guess is often a menu item or a random image.
The Open Graph protocol turns a web page into a rich object in a social graph, and it works by adding extra meta tags to the head of the page, as the protocol page at ogp.me explains. The tags are invisible to readers, but they shape every share of your content.
What are the four required Open Graph tags?
The protocol names four required properties for every page: og:title, og:type, og:image, and og:url.
Each tag uses the property attribute, not name, and holds its value in the content attribute. The four required tags, as listed on ogp.me, are the title of the object, its type, an image URL, and the canonical URL that serves as its permanent ID.
| Tag | What it controls |
|---|---|
og:title | The headline shown on the preview card |
og:type | The kind of page, such as website or article |
og:image | The image shown on the preview card |
og:url | The canonical URL of the page |
Three more tags are optional but recommended: og:description, a one to two sentence summary; og:site_name, the name of the whole site; and og:locale, the language of the page, which defaults to en_US. For articles, the protocol also defines article:published_time and article:modified_time.
If a page lists the same tag twice, the first one wins. The protocol states that the first tag from top to bottom is given preference during conflicts (ogp.me).
How do you add Open Graph tags with Yoast SEO?
Yoast SEO writes Open Graph tags for you, and the feature is on by default.
Yoast states on its help page that Open Graph data is enabled by default. To check the switch, go to Yoast SEO → Settings, open Site features, then Social sharing, and set the Open Graph data switch to On.
To set a custom preview for one post or page:
- Open the post or page in the editor.
- Open the Yoast SEO sidebar and go to Social media appearance.
- Set the image, title, and description for social sharing.
- Update the post.
Yoast builds the social title from your SEO title and the description from your meta description when you leave them blank. It also adds article:published_time and article:modified_time tags for posts, which Facebook uses to date the content.
If another plugin also outputs Open Graph tags, Yoast shows a warning that both plugins create Open Graph output. Disable the feature in one of the two plugins, or social sites may show the wrong title or image. Our Yoast setup guide covers the install and the first settings.
How do you add Open Graph tags with Rank Math?
Rank Math also writes Open Graph tags for every page, with settings for a default image and per-post overrides.
Rank Math lists the same four tags as essential for every page, og:title, og:type, og:url, and og:image, and recommends adding og:description on every page too (Rank Math). The plugin generates the og:type value from the content, so posts get article and other pages get website.
To set a default image for pages that have no featured image, go to Rank Math SEO → Titles & Meta → Global → OpenGraph Thumbnail, upload an image, and save. Rank Math documents that path in its image troubleshooting guide.
To set the image for one post, open the post, open Rank Math in the editor sidebar, and use the Social tab to upload a custom image. Rank Math also lets you set a separate thumbnail for the home page under Titles & Meta → Homepage.
How do you add Open Graph tags by hand in code?
Add the tags to the head of the page with a code snippet in a child theme or a code-snippets plugin.
The full set for a blog post looks like this:
<meta property="og:title" content="How to Add Open Graph Tags in WordPress" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://example.com/how-to-add-open-graph-tags-in-wordpress/" />
<meta property="og:image" content="https://example.com/images/open-graph-tags.png" />
<meta property="og:description" content="Add Open Graph tags with Yoast or Rank Math, or by hand in code." />
<meta property="og:site_name" content="Example Site" />
Use absolute URLs with https:// for og:url and og:image, never relative paths. Social crawlers fetch the image directly, and a relative path gives them nothing to fetch.
The og:type value should match the page: website for the home page and general pages, article for blog posts, and product for store products. Rank Math sets this for you when you use the plugin, but hand-written tags need the right value on each page type.
In WordPress, hook the tags to wp_head in a child theme or a code-snippets plugin. Do not edit the parent theme, since an update will wipe the change.
What image size should you use for Open Graph?
Use a 1200 by 630 pixel image, which is the widely used size for preview cards across the major platforms.
The 1200 by 630 size has a 1.91 to 1 ratio, so it fills the large card on Facebook, LinkedIn, Slack, and WhatsApp without awkward cropping. A 600 by 315 image still gets a large card on most platforms, while anything smaller shows as a small thumbnail.
Keep the file under 8 MB, and use JPEG for photos and PNG for graphics with text. Add the width and height to the tags so the crawler can lay out the card before it fetches the image:
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta property="og:image:alt" content="A preview card showing a blog post title and image" />
The protocol defines og:image:width, og:image:height, og:image:type, og:image:alt, and og:image:secure_url as structured properties of the image tag (ogp.me). The og:image:alt value describes what is in the image, and you should set it on every preview image.
What is the difference between Open Graph and Twitter Cards?
Open Graph tags control previews on Facebook, LinkedIn, Slack, and most chat apps, while Twitter Cards control previews on X.
X reads Open Graph tags as a fallback, but it prefers its own twitter:card tags.
The two card types are summary, which shows a small square image, and summary_large_image, which shows a wide image like the Open Graph card. Rank Math covers Twitter tags alongside Open Graph in its Open Graph guide.
Yoast and Rank Math write both sets of tags for you. When you set a social image in Yoast or Rank Math, the plugin outputs the Open Graph tags and the matching Twitter Card tags from the same image and title.
If you add tags by hand, add a twitter:card tag next to the Open Graph set:
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="How to Add Open Graph Tags in WordPress" />
<meta name="twitter:description" content="Add Open Graph tags with Yoast or Rank Math, or by hand in code." />
Note the difference: Open Graph tags use property, while Twitter Card tags use name. Mixing the two up is a common reason a card does not render.
How do you check that your Open Graph tags work?
Paste the URL into a sharing debugger and read the tags it finds.
Facebook offers a Sharing Debugger that shows the preview card and lists every Open Graph tag it scraped, plus any warnings. LinkedIn has a Post Inspector that does the same for its cards.
Before you test, view the page source in your browser and search for og:. You should see all four required tags, with full URLs and a real image address. If a tag is missing, check the plugin settings first, since a disabled social feature is the usual cause.
After you fix a tag, re-scrape the URL in the debugger. Facebook caches the preview, so an old title or image can keep showing until you ask it to fetch the page again.
Why is the wrong image or title showing when you share a link?
The wrong preview usually comes from a cached scrape, a missing featured image, or two plugins writing tags.
First, check for duplicates. If two plugins output Open Graph tags, the first set wins, and it may come from the plugin you did not expect. Yoast warns about this clash by name and tells you to switch the feature off in one plugin (Yoast).
Second, check the featured image. Yoast and Rank Math use the post featured image as the preview image when you do not set one. If the post has no featured image and no default is set, the platform picks a random image from the page, or shows none at all.
Third, clear the cache. Facebook stores the scraped preview, so a fix on your site does not change shares until the debugger re-scrapes the URL. Our schema markup guide covers another kind of markup that can affect how your pages appear in search and social results.
What mistakes should you avoid?
The most common mistake is leaving the preview image to chance and never checking a share.
- Do not use relative URLs for
og:imageorog:url; crawlers need full addresses. - Do not use
nameon an Open Graph tag; the protocol needsproperty. - Do not run two plugins that both write Open Graph tags; switch one off.
- Do not use a tiny or text-heavy image; keep the key detail near the center of a 1200 by 630 canvas.
- Do not skip the per-post settings on your most shared pages; the default image is a fallback, not a plan.
Share each key page once after you publish it, and look at the card before anyone else does. A quick check catches a missing image or a cut-off title while it is still easy to fix. For the rest of your on-page setup, our Yoast SEO guide explains what the plugin handles beyond social tags.
Frequently asked questions
Do Open Graph tags help my Google rankings?
No. Open Graph tags only shape the preview card when a link is shared. They do not change search rankings, and Google does not use them for ranking. They matter because a clear card with a good image earns more clicks from social feeds and chat apps, which brings more visitors.
Which is better for Open Graph, Yoast or Rank Math?
Both plugins write the same tags, so pick the one you already use. Yoast turns Open Graph on by default and puts the per-post settings in the Social media appearance tab. Rank Math adds the same controls under its Social tab, plus a default thumbnail setting. Use one plugin only.
What size should my Open Graph image be?
Use 1200 by 630 pixels, a 1.91 to 1 ratio. That size fills the large card on Facebook, LinkedIn, Slack, and WhatsApp. Smaller images still show, but as a small thumbnail. Keep the file under 8 MB, and use JPEG for photos and PNG for graphics with text.
Why does Facebook still show my old title after I fixed it?
Facebook caches the preview after its first scrape, so edits on your site do not change old shares at once. Open the Facebook Sharing Debugger, paste the URL, and ask it to scrape again. That pulls the fresh tags and rebuilds the card.
Do I need separate tags for X (Twitter)?
Add the twitter:card tag with the value summary_large_image, plus twitter:title and twitter:description. Open Graph tags use the property attribute, while Twitter Card tags use name. Yoast and Rank Math write both sets for you from the same social settings.
What happens if I leave out og:image?
The platform falls back to guessing from the page, and often picks a menu item, a footer line, or a random image. Set a featured image on every post and a default image in your SEO plugin, so there is always a real image for the card to use.
Sources
- The Open Graph protocol The Open Graph protocol
- How to add Facebook's Open Graph meta tags Yoast
- Open Graph Meta Tags Rank Math
- Yoast SEO plugin WordPress.org
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
