Add Google News Keywords Meta Tag to Thesis

thesisGoogle now has a meta tag for use in news articles called news_keywords. You can see an example below:

<meta name="news_keywords" content="World Cup, Brazil 2014, Spain vs Netherlands">

I wanted to add this to my site, but there’s no easy way to do it at the moment using Thesis or any WordPress plugins. So I decided to write some code and have it pull the keywords from the Thesis Keyword field on each post since I’m not currently using it.

To accomplish this, all you have to do is add the following code to your custom_functions.php file:

function head_code() { 
global $post;
?>
<meta name="news_keywords" content="<?php
if (get_post_meta($post->ID, 'thesis_keywords', true)) { 
echo get_post_meta($post->ID, 'thesis_keywords', true);
}
?>" />
<?php   
}
add_action('wp_head', 'head_code');

If you want to make a separate custom field just for news keywords, you can use the custom field feature and name it whatever you want, then replace ‘thesis_keywords’ in the above code with the new custom field name.

Related posts:

Previous post:

Next post: