• I am developing a theme where I need to enqueue jquery in footer and wrap it in conditional tags for browsers above IE10

    I tried using wp_script_add_data, which sort of worked, but resulted in this
    <!--[if gt IE 10]><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" defer="defer"></script><![endif]-->

    Which would be fine, however, non-IE browsers (Firefox, Chrome, etc) ignore this as a HTML comment.

    The standard solution I have been using for a long time for this problem is to write the condition like this
    <!--[if gt IE 10]><!--><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" defer="defer"></script><!--<![endif]-->

    (notice the extra <!–> at the beginning abd <!– at end)

    This makes non-IE browsers “unignore” the comment contents, and it is used as if it was written outside conditional tags.

    Is there a way I can get WordPress’s functions to output the include in format I need? Or some other way to include newer version of jQuery only in modern browsers (I am using the conditional tags with “add data” to include older jQuery and some fallbacks and polyfills in header for IE10 and lower)

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Enqueue jQuery in everything above IE10’ is closed to new replies.