Skip to content

Open Graph

Adding Open Graph tags in WordPress

By Hannah Voss, Editor · Reviewed September 2026 · 3 min read

Quick answer

Open Graph tags tell networks what title, description and image to show when your page is shared. In WordPress, let one SEO plugin output them, set a default image, and override the title, description and image per post where needed. Check the page source for duplicates from your theme or a share plugin, then test in each network's debugger.

On this page
  1. The tags that matter
  2. Option 1: one SEO plugin
  3. Option 2: theme code
  4. Why share plugins shipped their own tags
  5. Questions

The tags that matter

TagRequired by the protocolWhat it controls
og:titleYesHeadline on the preview card
og:typeYesUsually website or article
og:imageYesThe preview image
og:urlYesThe canonical address the share counts against
og:descriptionNoOne or two lines under the title
og:site_nameNoYour site name on some cards
og:image:width and og:image:heightNoLets the network lay out the card before downloading the image

Option 1: one SEO plugin

  1. Pick one source

    Most SEO plugins output Open Graph tags. Use exactly one plugin for them; turn off the same feature in your share plugin and theme.

  2. Set defaults

    Add a default share image, 1200 by 630 pixels, for pages without their own. See Open Graph image size.

  3. Override per post

    In the post editor's social settings, write a share title and description when the SEO title does not suit a social feed.

  4. Check the source

    View the page source and search for og:image. There should be one set of tags.

  5. Test

    Run the address through the Sharing Debugger and the LinkedIn Post Inspector.

Option 2: theme code

If you do not use an SEO plugin, print the tags from wp_head in your child theme. Use the post's featured image at a registered size of 1200 by 630, fall back to a site default, and escape every value.

add_action( 'wp_head', function () {
  if ( ! is_singular() ) { return; }
  $img = get_the_post_thumbnail_url( null, 'og-image' ) ?: 'https://example.com/default-share.png';
  printf( '<meta property="og:title" content="%s">', esc_attr( get_the_title() ) );
  printf( '<meta property="og:type" content="article">' );
  printf( '<meta property="og:url" content="%s">', esc_url( get_permalink() ) );
  printf( '<meta property="og:image" content="%s">', esc_url( $img ) );
} );

Why share plugins shipped their own tags

Some share plugins, MashShare with its Open Graph add-on among them, generated tags so that the image chosen for sharing matched the buttons. That made sense when few themes printed tags. Today it usually means two conflicting sets, which is the most common cause of the wrong image appearing on Facebook.

The Open Graph setup loop01One pluginoutputs tags02Page sourceone set only03Debuggerscrape again04Previewcorrect card
When the preview is wrong, go back to step two before anything else.

Questions

Do I need a plugin for Open Graph tags?

No, but an SEO plugin is the easiest way. Theme code in wp_head works if you escape every value.

Which Open Graph tags are required?

The protocol requires og:title, og:type, og:image and og:url. Description and image dimensions are strongly recommended.

Why do I have two sets of Open Graph tags?

Your theme, SEO plugin or share plugin each output tags. Turn the feature off in all but one.

Share this guide

Hannah Voss, Editor. Checks every guide against a working WordPress install and the networks' current documentation. Last reviewed September 2026.

  1. Facebook showing the wrong image or share textFix Facebook showing the wrong image or text when you share a WordPress post: duplicate tags, small images, cache, blocked crawlers, and the Sharing Debugger.3 min read
  2. Open Graph image size: 1200 by 630 and the safe zoneThe right Open Graph image size is 1200 by 630 pixels at a 1.91:1 ratio. Minimums, file limits, formats, and a centre safe zone for square crops.3 min read
  3. Twitter cards on X: tags and testingSet up Twitter card tags so links to your WordPress posts show a large image on X: the summary_large_image card, fallbacks to Open Graph, sizes and testing.3 min read