The official Facebook plugin does an excellent job of adding appropriate Open Graph meta tags to different pages (Home, Posts, Pages, Archives, etc.) of a WordPress site.
The problem is it does many things without my permission. Is there a way to get the functions responsible for adding Open Graph meta data from the plugin, so that I can add them to my theme’s functions.php?
The
fb-open-graph.php
(latest version’s file) right inside the extracted folder of the plugin is (solely) responsible for adding Open Graph meta data to the header of your site.Below is how I’ve modified the code in the file so that it’s fit to be added to your theme’s functions.php:
Notes:
Plugin version used: 1.0.1
Make sure the original plugin itself is deactivated first.
Replace
fb_get_locale()
withget_locale()
Remove (LINE 905):
And replace (LINE 906):
With this:
This fixes a bug in the plugin due to which it spurts out encoded HTML in the
og:description
meta tag (see Stephen Hariss’ comment).Replace this (LINES 151-154):
With this:
(replace FACEBOOK APP ID HERE with, well, your app ID â number)
I still have this plugin installed, BUT deactivated so that I can monitor updates from time to time, and make changes if necessary.