Wordpress - 仅适用于 IE 的排队脚本 [英] Wordpress - Enqueue script only for IE
问题描述
我想使用 dd belatedpng 以便我网站上的 PNG 在 IE 上正确显示.我一直在非 wordpress 网站上使用的脚本是
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]-->
现在我需要在 Wordpress 网站上使用它,我正在尝试找到一种使用 wp_enqueue_script 添加该脚本的方法(尽管我根本不喜欢该系统).归根结底,主题只会在一个网站上使用,我更愿意硬编码脚本路径.
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.
无论如何,有没有办法将 IE 条件添加到排队脚本和/或注册脚本中?
Anyway, is there a way of adding IE conditionals to enqueue script and or register script?
推荐答案
浏览器检测内置于 WordPress 中,使用全局变量 $is_IE
所以...
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' );
}
?>
对于您要执行的实际脚本,您可能应该将其添加到另一个以 dd_belatedpng
作为依赖项入队的文件中.
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.
这篇关于Wordpress - 仅适用于 IE 的排队脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!