Removing sharedaddy’s (jetbacks sharing) extra og:description without hacking php

I’ve come across a problem where multiple plugins insert facebook opengraph meta tags into the header of my posts without letting me turn that behavior on or off. They all assume that no one explicitly puts open graph tags in their blog. This includes sharedaddy (jetpack sharing). It does so with the following comment:

	public function display_header() {
		if ( $this->share_type == 'share' ) {
			// Set the open graph description, otherwise Facebook may pick up some random text from the page
			global $post;
			
			if ( $post && $post->ID > 0 )
				echo '<meta property="og:description" content="'.esc_attr( apply_filters( 'sharing_post_title', $post->post_title, $post->ID, $this->id ) ).'" />';
		}
	}

Source in wordpress trak.

Problem is I’d rather define my og tags or rely on a plugin focused on doing this well.

There are several plugins to do open graph tag insertion that do a better job. You may want to roll your own directly into your theme or using one of the general SEO plugins.

So, I want to remove these extraneous tags. Online tips suggest I go into each plugin and comment out the php code inserting these tags. That’s a direct option but I hate modifying plugins. I don’t want to maintain these hacks through updates.

So, I solved with javascript. The approach is a hack. It requires that sharedaddy and other plugins insert their og:description tags before the tags I want to preserve and that I start my desired facebook tags with an fb:admins tag.

function removeExtraOpenGraphMetaTags()
{
	//assumes extra og tags occur before an fb:admins
	var first_og_tag = jQuery("meta[property]").first();
        //if the first meta tag with a property attribute is fb:admins - do nothing
	if (jQuery("meta[property]").first().attr('property') != 'fb:admins') 
	{
		//remove all subsequent og tags until fb:admins
		var removed_tags = first_og_tag.nextUntil("meta[property='fb:admins']", "meta[property*='og:']").remove();
		if (removed_tags) { first_og_tag.remove(); }
	}
}

Technology IP Patents

Facebook patents news feeds in a social network context

The method covered in the patent includes “generating news items regarding activities associated with a user of a social network environment and attaching an informational link associated with at least one of the activities, to at least one of the news items, as well as limiting access to the news items to a predetermined set of viewers and assigning an order to the news items.” — PC World

Apple sues HTC for violations on 20 patents

Here’s the actual filing that includes the titles of each of the patents including:

  • Object oriented graphic system – granted 1995
  • List scrolling and document translation, scaling, and rotation on a touch-screen display – granted 2008
  • Object oriented event notification system with listener registration of both interests and methods – granted 2002

What kinds of Inventions can be Protected?

An invention must, in general, fulfill the following conditions to be protected by a patent. It must be of practical use; it must show an element of novelty, that is, some new characteristic which is not known in the body of existing knowledge in its technical field. This body of existing knowledge is called ” prior art“. The invention must show an inventive step which could not be deduced by a person with average knowledge of the technical field. Finally, its subject matter must be accepted as “patentable” under law. In many countries, scientific theories, mathematical methods, plant or animal varieties, discoveries of natural substances, commercial methods, or methods for medical treatment (as opposed to medical products) are generally not patentable. — World Intellectual Property Organization