Wp_deQueue_style和wp_deQueue_script在服务器上不起作用,但在本地xampp上起作用

时间:2017-12-27 作者:vanurag

这是我的全部代码,它在本地系统xampp中运行良好,但在服务器上不起作用。

function taqyeem_dequeue_scrips() {

   if(basename($_SERVER[\'REQUEST_URI\'])==\'my_page\' || basename($_SERVER[\'REQUEST_URI\'])==\'\')
    {
            wp_dequeue_style( \'taqyeem-style\' );
            wp_dequeue_script( \'taqyeem-main\' );
            wp_deregister_script( \'comment-reply\' );



    }
}
add_action( \'init\', \'taqyeem_dequeue_scrips\' );

function dequeue_scrips() {


if(basename($_SERVER[\'REQUEST_URI\'])==\'my_page\')
    {
            //css

            wp_dequeue_style( \'taxonomy-image-plugin-public\' );
            wp_dequeue_style( \'job-alerts-frontend\' );
            wp_dequeue_style(\'validate-engine-css\');
            wp_dequeue_style(\'cp-shortcode\');
            wp_dequeue_style(\'wsl-widget\');
            wp_dequeue_style(\'wp-job-manager-applications-frontend\');
            wp_dequeue_style(\'wp-job-manager-bookmarks-frontend\');
            wp_dequeue_style(\'wp-job-manager-resume-frontend\');



            wp_dequeue_style(\'wp-job-manager-frontend\');

            wp_dequeue_style(\'cp-widgets-css\');
            wp_dequeue_style(\'responsive-css\');
            wp_dequeue_style(\'owl-css\');
            wp_dequeue_style(\'svg-css\');
            wp_dequeue_style(\'cp-burgermenucss\');
            wp_dequeue_style(\'law-bx-slider-css\');
            wp_dequeue_style(\'prettyPhoto\');
            wp_dequeue_style(\'cp-bootstrap\');
            wp_dequeue_style(\'cp-wp-commerce\');

            wp_dequeue_style(\'cp-bx-slider\');

            wp_dequeue_style(\'googleFonts\');
            wp_dequeue_style(\'googleFonts-heading\');
            wp_dequeue_style(\'menu-googleFonts-heading\');
            wp_dequeue_style(\'wppb_stylesheet\');
            wp_dequeue_style(\'A2A_SHARE_SAVE\');

            //Script
            wp_dequeue_script( \'html5shiv\' );
            wp_dequeue_script( \'cp-bootstrap\' );
            wp_dequeue_script( \'addtoany\' );
            wp_dequeue_script( \'cp-owl-js\' );
            wp_dequeue_script( \'cp-velocity\' );
            wp_dequeue_script( \'owl-kenburns\' );
            wp_dequeue_script( \'cp-burgermenu\' );
            wp_dequeue_script( \'cp-burgermenucustom\' );
            wp_dequeue_script( \'cp-bx-slider\' );
            wp_dequeue_script( \'cp-custom\' );
            wp_dequeue_script( \'prettyPhoto\' );
            wp_dequeue_script( \'cp-pscript\' );
            wp_dequeue_script( \'cp-scripts_modernizr\' );
            wp_dequeue_script( \'cp-scripts\' );
            wp_dequeue_script( \'cp-scripts-workmark\' );
            wp_dequeue_script( \'cp-easing\' );
            wp_dequeue_script( \'cp-bx-slider\' );

    }
}
add_action( \'wp_enqueue_scripts\', \'dequeue_scrips\' );
请给我任何建议。我正在努力提高谷歌页面的速度,以便在移动和桌面上至少获得90分。目前移动设备性能较差(56)

2 个回复
SO网友:bravokeyl

如果要将脚本出列(&W);基于slug 页的。你可以通过各种方式获得slug,并使用它代替$_SERVER[\'REQUEST_URI\'].

使用if( is_page( array( \'my_page\') 而不是if(basename($_SERVER[\'REQUEST_URI\'])==\'my_page\')

function wpse_289574_dequeue_scrips() {
   if(is_page( array( \'my_page\')){
       wp_dequeue_style( \'taxonomy-image-plugin-public\' );
       ...       
   }
}

How to get the slug of a page:

$qo = $GLOBALS[\'wp_the_query\']->get_queried_object();
$cp = sanitize_post($qo);
$slug = $cp->post_name;
摘自:How to retrieve the slug of current page?

function wpse_289574_dequeue_scrips() {
   if($slug ==\'my_page\'){
       wp_dequeue_style( \'taxonomy-image-plugin-public\' );
       ...       
   }
}
当前出列挂钩为wp_enqueue_scripts.

SO网友:vanurag

我尝试了以下适用于我的代码:

add_action(\'get_header\', function() {
    if ( is_page( \'my_page\' ) ) {    
   add_action( \'init\', \'taqyeem_dequeue_scrips\' );
   add_action( \'wp_enqueue_scripts\', \'dequeue_scrips\' );

    }
});

结束

相关推荐

未调用WP_ENQUEUE_SCRIPTS挂接

我将以下代码添加到functions.php:if(!function_exists(\'bi_frontend_scripts\')) { function bi_frontend_scripts() { wp_enqueue_script(\'jquery\'); // I originally wanted to do: wp_enqueue_script(\'jQuery.bxSlider\', get_blo