1

I need to add this meta tag to every page in my site.

<meta http-equiv="X-UA-Compatible" content="IE=edge">

I found this PHP function on github

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

I tried adding it to my child theme functions.php file by downloading the file with FTP, adding this chunk to the end in a text editor, and then uploading it (via FileZilla).

This did not work, and viewing the HTML source files in the debugger showed that the meta tag did not appear. I don't have access to the individual HTML pages otherwise I would just add it manually.

And yes, I know IE sucks times a million, and its older versions are no longer supported, but I'm under strict orders to make it work. Also, I was just thrown into this wordpress mess yesterday having never done web development before (some coding background though). So explain it like I'm five please.

TL;DR: How do I add the same meta tag to every page on my StudioPress website? Also, from my understanding it needs to be in the header and as near the top as possible.

3

This function should take care for the input into the head of each page/post as asked.

Please make a copy of functions.php before adding following code.
Adjust to your own preferences if needed.

/**
 * Add meta to head
 *
 * Read more {@link https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head} 
 * @version Wordpress 4.8
 */
function wpse272951_wsm_keep_ie_modern() 
{
    echo "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/> \n";
} 
add_action( 'wp_head', 'wpse272951_wsm_keep_ie_modern' );

PS, it should not be added into the header as mentioned by you but into the head of a page between <head> </head> (which will be done by this function automatically).

  • Thanks so much! Does it matter where in the functions.php file I put it? – A.PSI Jul 11 '17 at 2:31
  • It is not important where in the functions.php as long it comes after the opening <?php. Cheers. (Please select the 'accept answer' marker so others will also know the function works and the topic is closed) – Charles Jul 11 '17 at 9:43
  • The tag appears, but it's far down in the head section, so by the time this tag is reached, the browser has already decided on a particular mode. I need to be able to put it right at the top (before the title, like the charset tag) – A.PSI Jul 11 '17 at 14:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.