How to Use if Statement for Meta Language Tag on Multi-Language Site

iflanguagemeta

Going through some SEO lists and found that magento websites do not provide the proper meta language information in the head on all pages.

Very simple to correct on uni-lingual websites, modify the head.phtml file located in /app/design/frontend/default/YOUR_THEME/template/page/html/

In the meta section add the following (replace en-CA with the correct language of your store):

<meta name="language" content="en-CA" />

To address the issue on a multiluange site I've composed the following code:

<div class="meta-language">

    <?php if($getStreId ==1) :?>
 <meta name="language" content="en-CA" /> 
        <?php endif; ?>
<meta name="language" content="fr-CA" /> 
            </div>

The site id 1 is for Enlish, the other will be French (2 languages).

When I inspect the code with Firebug I see the following:

<meta name="language" content="en-CA" />
<meta name="language" content="fr-CA" />

The expected result was to only see the active language for the meta language tag.

How can the code be modified to only show the active language ?

Best Answer

The if statement should also have an else, so it would be something like this

<div class="meta-language">
<?php if($getStreId ==1) :?>
   <meta name="language" content="en-CA" /> 
<?php else:    
   <meta name="language" content="fr-CA" /> 
<?php endif;?>
</div>

however there shouldn't be a <div> in the <head> section of your HTML. So you might want to drop that.

Also, there's not really a need to edit the head.phtml to add the <meta> tag. You can add the following to your local.xml

<?xml version="1.0" encoding="UTF-8"?>
<layout>
    <STORE_encastorecode>
       <default>
          <reference name="head">
              <block type="core/text" name="meta_language">
                 <action method="setText"><text><meta name="language" content="en-CA" /> </text></action>
              </block>
          </reference>
       </default>
    </STORE_encastorecode>
    <STORE_frcastorecode>
       <default>
          <reference name="head">
              <block type="core/text" name="meta_language">
                 <action method="setText"><text><meta name="language" content="fr-CA" /> </text></action>
              </block>
          </reference>
       </default>
    </STORE_frcastorecode>
</layout>

Just make sure you add the right storeview code to the <STORE> tag

Related Topic