【问题标题】:Is it possible to add stylesheet with an IE conditional comment when enqueing in wordpress?在 wordpress 中排队时是否可以添加带有 IE 条件注释的样式表?
【发布时间】:2013-04-22 21:50:31
【问题描述】:

我正在更新我自己构建的主题,并且已经轻松地进行了一些更改。

我的主题的样式表是通过functions.php文件中的wp_enqueue_style添加到页头的,如下:

function gridded_enqueue_styles() {
    wp_enqueue_style( 'themever-style', get_stylesheet_uri() );
wp_enqueue_style( 'bootstrap-css', get_stylesheet_directory_uri() .'/css/bootstrap.min.css' );
}

add_action('wp_enqueue_scripts', 'gridded_enqueue_styles');

样式表已加载,页面呈现,一切正常。

现在我需要添加一些带有 IE 条件注释的样式表,如下所示:

<!--[if IE 7]>
    <link rel='stylesheet' href='http://theme_path/css/ie7.css' type='text/css' media='all' />
<![endif]-->

有可能吗?

提前致谢。

【问题讨论】:

标签: wordpress wordpress-theming


【解决方案1】:

我注意到您已经解决了问题。您还可以查看以下代码以获取其他解决方案:

add_action( 'wp_head', 'wps_add_ie_html5_shim' );
/**
 *  Add IE conditional html5 shim to header
 */
function wps_add_ie_html5_shim() {
    global $is_IE;
    if ( $is_IE ) {
        echo '<!--[if lt IE 9]>';
        echo '<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>';
        echo '<![endif]-->';
    }
}

您也可以使用如下的 wordpress 全局变量检查特定的浏览器:

浏览器检测布尔值 这些全局变量存储有关用户在哪个浏览器上的数据。

$is_IE (boolean) Internet Explorer
$is_iphone (boolean) iPhone Safari
$is_chrome (boolean) Google Chrome
$is_safari (boolean) Safari
$is_NS4 (boolean) Netscape 4
$is_opera (boolean) Opera
$is_macIE (boolean) Mac Internet Explorer
$is_winIE (boolean) Windows Internet Explorer
$is_gecko (boolean) FireFox
$is_lynx (boolean)

欲了解更多信息:http://codex.wordpress.org/Global_Variables

【讨论】:

    【解决方案2】:

    我过去在 header.php 文件中做过,没有任何不良影响。

    【讨论】:

    • 在写插件的时候怎么办?我实际上想使用函数。因为主题将具有 on of 功能:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 2012-12-08
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    相关资源
    最近更新 更多