Skip to Content

Add X-UA-Compatible header in WordPress for Edublogs

On the University of Oregon instance of Edublogs we ran into a problem with the X-UA-Compatible meta tag. The standard practice of putting in the <head> did not work. A better solution was found using PHP:

if (isset($_SERVER['HTTP_USER_AGENT']) &&
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        header('X-UA-Compatible: IE=edge,chrome=1’);

For WordPress you can do the above using add_filter:

function example_add_headers($headers) {
        if (isset($_SERVER['HTTP_USER_AGENT']) &&
                (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) {
                $headers['X-UA-Compatible'] = 'IE=edge,chrome=1';
        }
        return $headers;
}

add_filter('wp_headers', 'example_add_headers');

Solutions taken from:

* http://www.validatethis.co.uk/news/fix-bad-value-x-ua-compatible-once-and-for-all/
* https://gist.github.com/chrisguitarguy/2712643