在WordPress中以正确的方式排列IE条件样式表

时间:2014-11-30 15:21:25

标签: css wordpress

我知道之前在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' );    

2 个答案:

答案 0 :(得分: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' );
}

答案 1 :(得分:0)

我没有看到任何可能妨碍你功能的事情。这是二十四个如何加载条件样式表

// 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' );