How to achieve precise control over the content inside the head element?

Yang Wen asked on September 15, 2015 16:38

In order to override browser-side compatibility view mode in IE, the following meta tag is needed. It must also be the very first element inside the head element (ignore the comment syntax)

<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

My issue is that Kentico 8.1 does not allow the page template to be modified such that we can specify the first element inside the head element. It looks like the title element is hardcoded to be the first element inside head.

What is the workaround to this issue?

Recent Answers


Brenden Kehren answered on September 15, 2015 18:12

I use the head HTML webpart and the Master Page properties of the page template. With the webpart you can add whatever you'd like and where it is on the page template is where it will load in the HEAD section. Typically place the tag you're talking about in the Master Page properties tab. Also note, I've never had an issue placing that meta tag in a webpart or in the Master Page properties. So NEEDING it to be the first element, isn't as critical as one might think, on my sites I have it as the 3rd element after title and the meta UTF tag and all works fine.

You can also utilize a script tag in your master page template layout like so:

    <script runat="server">
        public override void OnContentLoaded()
        {
            base.OnContentLoaded();
            CMS.UIControls.ContentPage page = this.Page as CMS.UIControls.ContentPage;
            if (page != null)
            {
                page.Header.Controls.Add(new LiteralControl("<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>"));
                page.XmlNamespace += "class=\"no-js\" lang=\"en\"";
            }
        }
    </script>
0 votesVote for this answer Mark as a Correct answer

Jeroen Fürst answered on September 16, 2015 21:33

You can also modify the physical portal template page which is located in: CMSPages\PortalTemplate.aspx. Just make sure to compare the file for changes when hotfixing/upgrading. Happy tweaking :)

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.