开发者

Is there a way to put php inside of a IE conditional comments

开发者 https://www.devze.com 2023-02-23 22:36 出处:网络
I have a php section that loads jquery through wordpress from google\'s api. I dont want to load jquery on IE browsers. Long story short, it doesn\'t work for whatever reason (you can read through my

I have a php section that loads jquery through wordpress from google's api. I dont want to load jquery on IE browsers. Long story short, it doesn't work for whatever reason (you can read through my other posted questions).

Or if this is not possible is there another way to NOT use this code when its an IE browser, maybe a php solution.

<?php 
    if( !is_admin()){
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enq开发者_运维技巧ueue_script('jquery');
    }

?>

Targets everything except IE (what i was trying to use, but it didnt work):

<!--[if !IE]><!-->
<!--<![endif]-->


You have the global $is_IE in Wordpress.


No. You'd probably want to detect the browser in a PHP block as an alternative solution. Something like:

$browser = get_browser();
if ($browser->browser == 'MSIE') {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enqueue_script('jquery');
    }
}

Or using the $is_IE global variable as in Nikolay Yordanov's answer:

if ($is_IE) {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js', false, '1.5.2', true);
        wp_enqueue_script('jquery');
    }
}


Short answer: no.

Long answer: IE conditional comments are client side, while PHP is server side, so it won't work.

Possible solution: http://php.net/manual/en/function.get-browser.php (or according to one of the answers already posted, wordpress provides a $is_IE global)

0

精彩评论

暂无评论...
验证码 换一张
取 消