调用wp_deQueue_script后对js和css的不必要请求调用

时间:2016-06-17 作者:user3234646

called unnecessary js and css request

http://www.example.com/wp-content/plugins/includes/js/jquery.form.min.js

http://www.example.com/wp-content/plugins/includes/js/scripts.js

orignal it was

http://www.example.com/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.jshttp://www.serpentcs.com/wp-content/plugins/contact-form-7/includes/js/scripts.js

这是在我在中编写函数后发生的function.php

// below function is used to deque script on certain page
function wpa_scripts() {
    // if this is not the contact page, remove the script
    if(!is_page(\'contact-us\') ){
        wp_dequeue_script( \'contact-form-7\' ); // only available onto contact-form-7
    }
    if(is_page( \'contact-us\' ) || is_page(\'blog-serpent-consulting-service\')){
        wp_dequeue_script( \'themepunchtools\' );
        wp_dequeue_script( \'fancybox\' );
        wp_dequeue_script( \'showbiz-jquery.themepunch.showbizpro.min\' );
        wp_dequeue_script( \'prettyphoto-js\' );      
        wp_dequeue_script( \'owl-js\' );              
        wp_dequeue_script( \'revmin\' );                      
    }
}
 //adjust priority to make sure this runs after the plugins add their scripts/styles
add_action( \'wp_print_scripts\', \'wpa_scripts\', 100 );
在我删除一个仍然调用js和css文件的函数之后。

after change add_action( \'wp_print_scripts\', \'wpa_scripts\', 100 );add_action( \'wp_enqueue_scripts\', \'wpa_scripts\', 100 );

工作正常所有页面但不在“联系我们”页面

它包含以下链接

http://www.example.com/wp-content/plugins/includes/js/jquery.form.min.js

http://www.example.com/wp-content/plugins/includes/js/scripts.js

我需要

http://www.example.com/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.jshttp://www.serpentcs.com/wp-content/plugins/contact-form-7/includes/js/scripts.js

1 个回复
最合适的回答,由SO网友:Pierre 整理而成

要使用的挂钩是wp_enqueue_scripts 而不是wp_print_scripts