jxycms
11/23/2016 - 2:33 AM

add hreflang in kentico website

add hreflang in kentico website

*add hreflang tag to website
//add to head in master page
<link rel="alternate" href="{%protocol%}://www.power2motivate.com.au{% CMSContext.CurrentDocument.NodeAliasPath #%}" hreflang="en-AU" />
<link rel="alternate" href="{%protocol%}://www.power2motivate.co.uk{% CMSContext.CurrentDocument.NodeAliasPath #%}" hreflang="en-GB" />
<link rel="alternate" href="{%protocol%}://www.power2motivate.com{% CMSContext.CurrentDocument.NodeAliasPath #%}" hreflang="en-US" />
<link rel="alternate" href="{%protocol%}://www.power2motivate.asia{% CMSContext.CurrentDocument.NodeAliasPath #%}" hreflang="en" />
<link rel="alternate" href="{%protocol%}://www.power2motivate.ca{% CMSContext.CurrentDocument.NodeAliasPath #%}" hreflang="en-CA" />
//add to layout in master page
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
    if (CurrentDocument != null)
    {          
        CMS.UIControls.ContentPage page= this.Page as CMS.UIControls.ContentPage;
        if (page != null)
        {
            string lang= CMS.Localization.LocalizationContext.CurrentCulture.CultureCode;
            page.XmlNamespace += " lang=\"" + lang + "\"";
        }
    }
}
</script>