Google Site Verification Meta Tag in Drupal / Zen
When verifying a site for Google Webmaster Tools, one of the options uses meta tags, specifically meta name="google-site-verification".
This meta tag only needs to appear on the front page of the site, so we can easily check for "is_front" in Drupal and add the meta tag using the theme_preprocess_page() function.
In the Zen theme (as well as Genesis and many other Drupal themes), headers can easily be added by manipulating $vars['head'] string in the existing theme_preprocess_page(). So to add the google-site-verification meta tag to most themes or sub-themes, it would look something like this:
<?php
function THEMENAME_preprocess_page(&$vars, $hook) {
// Other proprocess code is probably already here...
// ...
// Put Google site verification on the front page only
if ($vars['is_front']){
$vars['head'] .= '<meta name="google-site-verification" content="GOOGLE_CODE_HERE" />'."\n";
}
}
?>If you are using a theme other than Zen or Genesis, this code should still work, but you may need to replace $vars[] with a different variable. Note the name of the first parameter to THEMENAME_preprocess_page(), and use it instead of $vars[] if it is different.
Comments
#1 nodewords.module
Submitted by Eric Weik on Mon, 12/07/2009 - 16:50.
I should point out that for anything beyond the extremely simple case presented here, it is also worth exploring the most excellent and flexible nodewords module for Drupal. It adds per-node meta descriptions, keywords, etc. as well as verification tags for Google, Yahoo, and Bing.
#2 Upgrade
Submitted by Riftstalker (not verified) on Tue, 02/08/2011 - 05:15.
Is that Drupal 7 only? We have been stuck to Drupal 6 for our online RPG. Our custom theme fails all kinds of checks ... I guess we need to upgrade to 7 and migrate to Zen, right?
#3 This is Drupal 6
Submitted by Eric Weik on Wed, 02/16/2011 - 09:23.
I need to go through and update the taxonomy on the site to make it clear what versions things work on, but in this case, the above article is about Drupal 6.
-Eric
Post new comment