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.

1 Answer
1

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).

Leave a Reply

Your email address will not be published. Required fields are marked *