WordPress – Enqueue script only for IE

I want to use dd belatedpng so the PNG’s on my website appear properly on IE. The script I’ve always used on non-wordpress websites was

<!--[if lt IE 7 ]>
    <script src="js/dd_belatedpng.js"></script>
    <script> DD_belatedPNG.fix('img, .ir'); </script>
<![endif]-->

Now that I need to use it on a WordPress website, I’m trying to find a way of adding that script using wp_enqueue_script (although I don’t like that system at all). At the end of the day, the theme is only going to be used on a single website, I’d prefer to hardcode the scripts path.

Read More

Anyway, is there a way of adding IE conditionals to enqueue script and or register script?

Related posts

Leave a Reply

2 comments

  1. The browser detection is built into WordPress with the global variable $is_IE so…

    <?php
    global $is_IE;
    if ( $is_IE ) {
        wp_enqueue_script( 'dd_belatedpng', bloginfo('template_directory').'/js/dd_belatedpng.js' );
    }
    ?>
    

    For the actual script you want to execute, you should probably add it to another file that is enqueued with dd_belatedpng as a dependency.

  2. What if you used PHP to detect the browser in the functions.php file and then put a simple if/else statement to it?

      if (isset($_SERVER['HTTP_USER_AGENT']) && 
        (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)){
            wp_enqueue_script('jquery');
        } else {
            return false; }