Wordpress - 仅针对IE排队脚本

Jos*_*ino 5 wordpress

我想使用dd belatedpng,以便我的网站上的PNG在IE上正常显示.我一直在非wordpress网站上使用的脚本是

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

现在我需要在Wordpress网站上使用它,我试图找到一种使用wp_enqueue_script添加该脚本的方法(尽管我根本不喜欢那个系统).在一天结束时,主题只会在一个网站上使用,我更喜欢硬编码脚本路径.

无论如何,有没有办法添加IE条件来排队脚本和/或注册脚本?

小智 12

使用全局变量将浏览器检测内置到WordPress中$is_IE......

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

对于要执行的实际脚本,您应该将其添加到另一个dd_belatedpng作为依赖项排队的文件中.