addOpenGraphData: Open Graph Protocol in Fork

With the 2.6.0-release we introduced some new methods to handle meta-information:

  • addLink: add a link-item (e.g.: stylesheet, rssfeed, ...)
  • addMetaData: add a meta-tag (e.g.: keywords, robots, ...)
  • addMetaDescription: add a meta-description
  • addMetaKeywords: add meta-keywords
  • addOpenGraphData: add Open Graph data

I'm not going to explain each of these methods in detail. They are pretty self-explanatory. All you should know is that they won't overwrite the current value, unless you tell them to do so. This is for all meta-tags, except for the meta-keywords-tag, meta-description-tag and meta-robots-tag. For these specific items the value will be appended.

One method I want to explain somewhat more in depth: addOpenGraphData.

What is the Open Graph Protocol?

The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to enable any web page to have the same functionality as a Facebook Page.

Basicaly it means that you add some info into the HTML of your page, that other websites (like Facebook) can use to build a correct and rich snippet of your site.

What about Fork?

In Fork it is implemented by default in the Blog-module. The only thing you need to do is add your Facebook profile-id in the Settings-tab. When that is done, you can check the source-code for a blog-article. If you look in the head-section you will see all Open Graph data is present.

How can I do this in my own module?

The only thing you need to do is using the addOpenGraphData-method. It has 3 arguments:

  • $key: the Open Graph-property (you don't need to include the og:-part).
  • $value: the value for the property.
  • $overwrite: should the current value be overwriten. In most cases this will be true.

How can I verify the result?

If you put a lot of time in setting the correct tags, it would be nice to verify the result. Well, at you can test your page.

So if you are building a new module, try it out and make it easy to share the correct content on Facebook (or any other platform that supports Open Graph Data). If you have any questions or remarks, feel free to post them below.