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.
Anyway, is there a way of adding IE conditionals to enqueue script and or register script?
To enqueue scripts and styles in the front-end you'll need to use the wp_enqueue_scripts hook. Within the hooked function you can use the wp_register_script() , wp_enqueue_script() , wp_register_style() and wp_enqueue_style() functions.
Notes. The function should be called using the wp_enqueue_scripts action hook if you want to call it on the front-end of the site, like in the examples above. To call it on the administration screens, use the admin_enqueue_scripts action hook. For the login screen, use the login_enqueue_scripts action hook.
The recommended way of enqueuing the stylesheets is to add a wp_enqueue_scripts action and use wp_enqueue_style() in your child theme's functions.php . If you do not have one, create a functions.php in your child theme's directory.
To add the script in the footer or bottom of a WordPress page, all you need to do is set the $in_footer parameter to true . We have also used another function get_template_directory_uri() which returns the URL for the template directory.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With