Meta tags are an easy way to add verification to your Magento store for Google Webmaster Tools, Bing Webmaster Tools, Yandex.Webmaster, and Pinterest for Business accounts. In this article, we’ll go over two easy ways to add these tags to your Magento store.
One alternative to adding meta tags is to upload a file from each of these sites to your site’s root directory. Unfortunately, when developers, IT, and version control systems are involved, this can be a much longer process than it should be. Instead of taking a few seconds, it may take days or even weeks just to get a new file (let alone four) uploaded to the root directory of your store.
Thankfully, Magento provides a couple of workaround for this, one that is extremely simple, and one that is a little more sophisticaned but cleaner and easier to read and maintain. We’ll start with the simpler method.
Miscellaneous Head Scripts
Log in to the admin section of your store, and navigate to System > Configuration > Design > HTML Head > Miscellaneous Scripts, and simply copy-paste the verification code there.
The code for our TrafficMotion website would look like this:
<meta name="msvalidate.01" content="14B60B177AD73A9CB88E52E10DE81E9F" /> <meta name="google-site-verification" content="Y0KjL1s3sCz5_RnzmBPdNIiMKE7n-iPy3OzjlRlPvdI" /> <meta name="p:domain_verify" content="8c5c5b782d04896448cc802df0e4e97b" /> <meta name='yandex-verification' content='7754504dbf4109f0' />
Easy, right? So what’s the problem with this method?
There really isn’t one, but the scripts are added to the <head> of every page of your site, where Google, Bing, Yandex, and Pinterest only require it on the home page.
To put it simply, why clutter up every page of your site, when you don’t need to? Google or Bing aren’t going to bother verifying the tag on every single page of your store, so why bother including it? It’s just extraneous code for the vast, vast majority of your pages.
So let’s add these pieces of code a different way, and just get them on the home page.
Block & Layout Update
First, navigate to System > Configuration > General > Content Management > WYSIWYG Options. We’re going to change the setting for “Enable WYSIWYG Editor” to “Disabled by Default.” If we don’t do that, Magento’s WYSIWYG editor will strip out the meta tags we’ll be adding to a new static block.
Adding a New CMS Static Block
Once you’ve done that, go to CMS > Static Blocks > Add New Block. You can name it anything you want, but we’ll give it the Block Title of “Validation Codes” and the Identifier of “html_validation_codes” for the purposes of this tutorial.
Then, in the Content, copy-paste in your meta tag verification codes. Now, we just have to get that block into our home page.
Adding the Validation Codes Block to the Home Page
Now, go to CMS > Pages > Home page, and hit the Design Tab under Page Information. This is the part where it can get tricky for new store owners, but it’s really not too difficult.
There may already be some code in the Layout Update XML field if you’re using the base default theme, or it may be empty. In either event, we’re going to add a little snippet of code to reference our Validation Codes static block. Here’s what you would include if you’ve followed along so far:
<reference name="head"> <block type="cms/block" name="validation_code"> <action method="setBlockId"><block_id>html_validation_codes</block_id></action> </block> </reference>
Wrapping Up Validation Codes
Now, check the Page Source of your Magento store home page, and you should see the block of code just under our customized Google Analytics code. It looks just like this:
Then, you can check for the code on any other page of your website, and it won’t be there! It’s not a huge savings in terms of the amount of HTML on the page, but it does keep a few lines of extraneous code off of them. No website would pay much attention to those meta tags if they were on every page anyway, so let’s keep the category, CMS, and product pages a little cleaner.