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.
Post new comment