【问题标题】:Enqueueing IE conditional stylesheets in WordPress the right way以正确的方式在 WordPress 中将 IE 条件样式表排入队列
【发布时间】:2014-12-01 00:29:24
【问题描述】:

我知道这个问题之前在 stackoverflow 上被问过,但在我的一生中,我无法让我的条件样式表加载并适用于所有版本的 IE。我感谢提前提供的任何帮助,这真的很影响我,我不知道从这里开始做什么。我还尝试在标题中加载 IE 样式表,但这似乎也不起作用。我的主题不是子主题。

这是我的函数代码:

function theme_styles() {

global $wp_styles;

wp_enqueue_style( 'bootstrap_css', get_template_directory_uri() . '/css/bootstrap.min.css' );
wp_enqueue_style( 'glyphicons_css', get_template_directory_uri() . '/css/glyphicons.css' );
wp_enqueue_style( 'glyphiconssocial_css', get_template_directory_uri() . '/css/social.css' );
wp_enqueue_style( 'main_css', get_template_directory_uri() . '/style.css' );

    /**
 * Load our IE-only stylesheet for all versions of IE:
 * <!--[if IE]> ... <![endif]-->
 * 
 * NOTE: It is also possible to just check and see if the $is_IE global in WordPress is set to true before 
 * calling the wp_enqueue_style() function.  If you are trying to load a stylesheet for all browsers 
 * EXCEPT for IE, then you would HAVE to check the $is_IE global since WordPress doesn't have a way to 
 * properly handle non-IE conditional comments.
 */
wp_enqueue_style( 'ie_css', get_template_directory_uri() . '/ie.css', array('bootstrap_css', 'main_css')  );
$wp_styles->add_data( 'ie_css', 'conditional', 'IE' );


} add_action( 'wp_enqueue_scripts', 'theme_styles' );    

【问题讨论】:

    标签: css wordpress


    【解决方案1】:

    这种方法效果很好。请注意,注释样式在 FF Firebug 中似乎是不可见的,而在 Chrome 开发人员工具中它们会显示。

    add_action( 'wp_enqueue_scripts', 'so27214782_wp_enqueue_scripts' );
    function so27214782_wp_enqueue_scripts()
    {
        global $wp_styles;
    
        wp_enqueue_style( 'so27214782_ie', get_template_directory_uri() . '/ie.css', array(), '27214782', 'all' );
    
        $wp_styles->add_data( 'so27214782_ie', 'conditional', 'IE 6' );
    }
    

    【讨论】:

    • 谢谢你,终于到了,我是个杜夫。学习失败!
    【解决方案2】:

    我没有看到任何可能妨碍您的功能的东西。下面是二十四加载条件样式表的方法

    // Load the Internet Explorer specific stylesheet.
    wp_enqueue_style( 'twentyfourteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentyfourteen-style', 'genericons' ), '20131205' );
    wp_style_add_data( 'twentyfourteen-ie', 'conditional', 'lt IE 9' );
    

    【讨论】:

    • 谢谢,终于搞清楚到底哪里错了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    相关资源
    最近更新 更多