Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 script using enqueue script, although I don't like it 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.

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

share|improve this question
add comment

3 Answers 3

up vote 5 down vote accepted

WordPress has a $is_IE global variable:

global $is_IE;
if($is_IE) enqueue_script(...);

Personally I prefer the IE conditional comments. Other browsers ignore them anyway, so there's no reason to use PHP for browser detection.

You might also want to consider using 8 bit alpha PNG images instead of 24 bit PNGs, which don't need any javascript fix in IE, and in most cases they will look the same as a 24 bit PNG.

share|improve this answer
    
Amoeba - Slight error in your example, the enqueue function call. –  t31os Jan 9 '11 at 16:52
    
thanks. you're right, it's wp_enqueue_script() –  onetrickpony Jan 9 '11 at 17:18
add comment

Enqueue doesn't support output of more complex blocks, only script files.

Best approach for this would be small function that echoes this block (conditionally if you don't need it on every single page), hooked to wp_head.

share|improve this answer
add comment

Adding to Rarst's answer, this can be done similar to the following, in your functions file.

add_action( 'wp_head', 'add_belatedpng_js' );

if ( ! function_exists( 'add_belatedpng_js' ) ) {
  function add_belatedpng_js() {

   if (! is_admin()) {      
    echo '
    <!--[if lt IE 7]>
      <script src="js/dd_belatedpng.js"></script>
      <script> DD_belatedPNG.fix('img, .ir'); </script>
    <![endif]-->';
 }
}
share|improve this answer
1  
Some accompanying words (plain text, not code) would be nice, too. –  t f Jan 16 at 15:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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