Improve Social Sharing with Open Graph Protocol Tags

Add Open Graph tags so shared links show the right title, description and image.

  • Open Graph Protocol (OGP) tags let you control the images, titles, descriptions and metadata that major social networks (Facebook, Twitter, Google Plus, LinkedIn) display when your content is shared.
  • Setup step 1: add the required RDFa namespace attributes (xmlns, xmlns:og, xmlns:fb) to your html tag. OGP tags will not work without them; lang and xml:lang are optional but recommended.
  • Setup step 2: add OGP meta tags to the head section of your HTML. Key tags include og:title, og:type, og:url, og:image, og:description, og:site_name, og:locale, plus fb:page_id and fb:admins for Facebook integration.
  • Best practices: use a 300x300 pixel square image for og:image and keep og:description to about 115 characters. The og:url is also used to calculate your share count.
  • After implementing, verify your tags with the Facebook URL Debugger, Google+ Rich Snippets Testing Tool, or Open Graph Data Viewer.
  • For WordPress, the easiest options are the WordPress SEO by Yoast plugin (under its Social menu) or the stand-alone Open Graph Pro plugin.

Facebook Open Graph Protocol ExampleAllowing your users to share your content in the easiest, best way possible is important these days. With the help of Open Graph Protocol you can easily control the images, titles, descriptions and other metadata that is used by major social networks including Facebook, Twitter, Google Plus & LinkedIn.

RDFa Attributes

The first step to setting up Open Graph Protocol tags on your website is to add the proper RDFa attributes to the html tag at the top of your website.

<html lang="en-US" xml:lang="en-US" xmlns="https://www.w3.org/1999/xhtml" xmlns:og="https://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">

The lang and xml:lang are not required attributes, but are good to have for various reasons. The xmlns, xmlns:og and xmlns:fb tags are required. The Open Graph Protocol tags will not work without them.

Open Graph Protocol Meta Tags

On to the good stuff, the OGP meta tags themselves. These can be added to the head section of your HTML document below your other tags. There are additional tags available, I’ve chosen to focus on a few of the most common ones.

<meta property="og:title" content="Professional WordPress Web Design & Development" />
<meta property="og:type" content="website" />
<meta property="og:url" content="/" />
<meta property="og:image" content="/wp-content/themes/kevinleary-v2/images/kevin-leary-open-graph-logo.png" />
<meta property="og:description" content="A web designer &amp; developer specializing in customized WordPress theme design, plugin development and online marketing in Boston, MA." />
<meta property="og:site_name" content="kevinleary.net" />
<meta property="og:locale" content="en_US" />
<meta property="fb:page_id" content="146928647585"/>
<meta property="fb:admins" content="bostonwordpressdesign"/>

What Do These Mean?

Each tag translates into the following:

  1. og:title — The title that will be used when this page is shared
  2. og:type — The type of resource that best describes your page
  3. og:url — The web address that will be shared, and will be used to calculate the share count
  4. og:image — An image to be shared (300×300 pixel square works well)
  5. og:description — A 115 character description that will appear when this page is shared.
  6. og:site_name — The name of your website.
  7. og:locale — The locale, or language location for your content.
  8. fb:admins — The Facebook ID’s of admins that manage a corresponding Facebook page. Each Facebook page has a Facebook “user” that can post updates to anyone that follows the page.
  9. fb:page_id — The Facebook Page ID for an associated Facebook page. Your page will appear in the “Likes and Interests” section of the user’s profile, and you have the ability to publish updates to the user.

Verifying The Results

Once you have your OGP meta tags in place you’ll want to verify that the data you have provided is being received properly by all sources. There are a few great tools our there that make this process simple:

Open Graph Protocol Tags in WordPress

There are many ways to add OGP tags to your WordPress website, I would recommend the following plugins:

  • WordPress SEO by Yoast Plugin — Yoast has included the Open Graph Protocol tags under the Social menu. The Facebook integration he added in the recent 1.1.2 update couldn’t be easier.
  • Open Graph Pro Plugin — This is a stand-alone OGP plugin that makes the setup process very easy.

Resume