← All field notes

engineering / October 11, 2012

How to Add Google News Meta with Wordpress Tags

Google News works well already, but why not help it out? Add a few tags. Your rank might thank you.

Editorial blueprint illustration for How to Add Google News Meta with Wordpress Tags
Original Esotech field note / illustration generated for this archive

Add this code to your functions.php in your Wordpress Themes folder to automatically add "news_keywords" into your HTML. The news_keywords meta is a new way to tag news articles that allows webmasters to assist Google News in categorizing posts.

/*
 * Title: News Meta Function
 * Author: Alexander Conroy
 * Version: 1.0.1
 * Website: http://www.esotech.org
 * Purpose: Tags Tags for Current Post and puts it in the header meta comma separated maximum 10 tags.
 * License: GPLv3+
*/

add_action('wp_head', 'news_meta');
function news_meta() {
	$posttags = get_the_tags();
	if ($posttags):
		$count = 1;
		foreach($posttags as $tag) :
			if($count == 10) break;
	    		$meta_tags[] = $tag->name;
			$count++;
		endforeach;
		$meta_tags_text = implode(',', $meta_tags); 
		echo '' . PHP_EOL;
	endif;
}