简体   繁体   English

Wordpress Bootstrap html5 wp_enqueue_style

[英]Wordpress Bootstrap html5 wp_enqueue_style

I'm trying to wp_style_add_data for bootstrap for html5shiv.min.js and respond.min.js 我正在尝试wp_style_add_data进行html5shiv.min.js和response.min.js的引导

Tried: 尝试:

wp_enqueue_style( 'theme-ie', 'https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js', array( 'theme-style' ), '3.7.2' );
wp_enqueue_style( 'theme-ie-2', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', array( 'theme-style' ), '1.4.2' );
wp_style_add_data( 'theme-ie', 'conditional', 'lt IE 9' );
wp_style_add_data( 'theme-ie-2', 'conditional', 'lt IE 9' );

But this is adding if lt IE 9 twice: 但这是如果IE 9两次的话:

<!--[if lt IE 9]>
<link rel='stylesheet' id='theme-ie-css'  href='https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js?ver=3.7.2' type='text/css' media='all' />
<![endif]-->
<!--[if lt IE 9]>
<link rel='stylesheet' id='theme-ie-2-css'  href='https://oss.maxcdn.com/respond/1.4.2/respond.min.js?ver=1.4.2' type='text/css' media='all' />
<![endif]-->

it's possible to add html5shiv and respond scripts within same if lt IE 9 using wp_style_add_data, or is neccesary to add codes manually to wordpress header.php? 是否有可能添加html5shiv并在同一脚本中响应脚本(如果使用wp_style_add_data的IE 9),还是需要手动将代码添加到wordpress header.php?

Use script_loader_tag : 使用script_loader_tag

// Conditional polyfills
$conditional_scripts = array(
    'html5shiv'           => '//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv.js',
    'html5shiv-printshiv' => '//cdn.jsdelivr.net/html5shiv/3.7.2/html5shiv-printshiv.js',
    'respond'             => '//cdn.jsdelivr.net/respond/1.4.2/respond.min.js'
);
foreach ( $conditional_scripts as $handle => $src ) {
    wp_enqueue_script( $handle, $src, array(), '', false );
}
add_filter( 'script_loader_tag', function( $tag, $handle ) use ( $conditional_scripts ) {
    if ( array_key_exists( $handle, $conditional_scripts ) ) {
        $tag = "<!--[if lt IE 9]>$tag<![endif]-->";
    }
    return $tag;
}, 10, 2 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM