WordPress - Enqueue scripts for only if LT IE 9

前端 未结 7 764
无人及你
无人及你 2021-01-31 09:13

In a WordPress theme, how do you conditionally include scripts for ie8 and below? This is primarily to apply polyfills for various html5/css3 features. I see that wp has the $is

7条回答
  •  天命终不由人
    2021-01-31 09:54

    Update for WordPress 4.7.3 with scripts loading from CDN:

        add_action( 'wp_enqueue_scripts', 'load_IE_fallback' );
    function load_IE_fallback() {
        wp_register_script( 'ie_html5shiv', 'https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js', '', '3.7.3', false );
        wp_register_script( 'ie_respond', 'https://oss.maxcdn.com/respond/1.4.2/respond.min.js', '', '1.4.2', false );
    
        wp_enqueue_script( 'ie_html5shiv');
        wp_enqueue_script( 'ie_respond');
    
        wp_script_add_data( 'ie_html5shiv', 'conditional', 'lt IE 9' );    
        wp_script_add_data( 'ie_respond', 'conditional', 'lt IE 9' );
    }
    

提交回复
热议问题