Disabling Open Graph from Facebook’s official WordPress plugin

I was looking for a way to remove the OG meta because Facebook’s OG Object Debugger tool kept throwing this really annoying error to do with multiple og:url values. Something like this:

Object at URL ‘http://website.com/test-article/’ of type ‘article’ is invalid because it specifies multiple ‘og:url’ values:

I checked my source code multiple times, it was clean but it just refused to quit unless I disabled the Facebook plugin. The catch here was that I really wanted to have Facebook comments integrated and none of the other third-party plugins made it an easy job, so I had to have the Facebook plugin back regardless.

Then I found this thread, but saying “If you want to remove the Open Graph protocol content output by the Facebook plugin for WordPress you should unhook the Facebook_Open_Graph_Protocol::add_og_protocol function from the wp_head WordPress action.” isn’t very helpful to someone who’s been shamefully remiss with his WP-fu skills.

It took a lot of searching to get this snippet, so if you’re looking for a way to disable the built-in OG (or Open Graph) data that Facebook’s official WordPress plugin spews, here you go.  Courtesy of aendrew from the WordPress forums.

/**
* OpenGraph stuff is now handled by Yoast or whatever.
* This removes Facebook's broken use of its own technology.
*/
add_action('wp_head', 'remove_fb_og_stuff', 0);
function remove_fb_og_stuff() {
remove_action( 'wp_head', 'Facebook_Open_Graph_Protocol::add_og_protocol' );
}

Good luck and if you found this useful, feel free to share this with someone else who needs it.

Update: Disabling the action inside Facebook’s plugin seems to work better. The above code killed every possible OG being output by all plugins for some reason.

Comment the below line from facebook.php inside the Facebook plugin’s directory. It’s on line 465 if you’re using the same version. I then used Facebook Open Graph Meta Tags for WordPress to output the OG meta tags I needed.

// add_action( 'wp_head', array( 'Facebook_Open_Graph_Protocol', 'add_og_protocol' ) );

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s