我正在为此而苦苦挣扎,但是我想做的是加快WooCommerce后端的速度。我现在大约是10秒,我希望通过消除正在加载的任何不需要的脚本和CSS来节省几秒钟的时间。
我只是想消除后端的这些请求,特别是WooCommerce的订单页面和单个订单页面。我开玩笑地将add_action
放在函数的上方和下方,但是什么也没有。
add_action( 'admin_init', 'remove_admin_styles', 999 );
function remove_admin_styles()
{
// Dequeue
wp_dequeue_style( 'caldera-forms-admin-icon-styles' );
wp_dequeue_style( 'et-core-admin' );
wp_dequeue_style( 'et-core-portability' );
wp_dequeue_style( 'wf-common-style' );
wp_dequeue_style( 'wf-fedex-style' );
wp_dequeue_style( 'woocommercebulkdiscount-style-admin' );
wp_dequeue_style( 'tm_epo_admin_css' );
wp_dequeue_style( 'tc-font-awesome' );
wp_dequeue_style( 'tm_global_epo_animate_css' );
wp_dequeue_style( 'tm_global_epo_admin_css' );
wp_dequeue_style( 'tm_global_epo_admin_font' );
wp_dequeue_style( 'tm-spectrum' );
wp_dequeue_style( 'tc-font-awesome' );
wp_dequeue_style( 'yoast-seo-admin-global' );
wp_dequeue_style( 'yoast-seo-dismissible' );
wp_dequeue_style( 'et-meta-box-style' );
wp_dequeue_style( 'et-core-version-rollback' );
wp_dequeue_style( 'library-menu-styles' );
wp_dequeue_style( 'woocommerce_admin_menu_styles' );
wp_dequeue_style( 'woocommerce_admin_styles' );
wp_dequeue_style( 'yoast-seo-toggle-switch' );
wp_dequeue_style( 'yoast-seo-admin-css' );
wp_dequeue_style( 'woocommerce-activation' );
wp_dequeue_style( 'dashicons' );
// Deregister
wp_deregister_style( 'caldera-forms-admin-icon-styles' );
wp_deregister_style( 'et-core-admin' );
wp_deregister_style( 'et-core-portability' );
wp_deregister_style( 'wf-common-style' );
wp_deregister_style( 'wf-fedex-style' );
wp_deregister_style( 'woocommercebulkdiscount-style-admin' );
wp_deregister_style( 'tm_epo_admin_css' );
wp_deregister_style( 'tc-font-awesome' );
wp_deregister_style( 'tm_global_epo_animate_css' );
wp_deregister_style( 'tm_global_epo_admin_css' );
wp_deregister_style( 'tm_global_epo_admin_font' );
wp_deregister_style( 'tm-spectrum' );
wp_deregister_style( 'tc-font-awesome' );
wp_deregister_style( 'yoast-seo-admin-global' );
wp_deregister_style( 'yoast-seo-dismissible' );
wp_deregister_style( 'et-meta-box-style' );
wp_deregister_style( 'et-core-version-rollback' );
wp_deregister_style( 'library-menu-styles' );
wp_deregister_style( 'woocommerce_admin_menu_styles' );
wp_deregister_style( 'woocommerce_admin_styles' );
wp_deregister_style( 'yoast-seo-toggle-switch' );
wp_deregister_style( 'yoast-seo-admin-css' );
wp_deregister_style( 'woocommerce-activation' );
wp_deregister_style( 'dashicons' );
}
答案 0 :(得分:0)
挂钩admin_init
在admin_enqueue_scripts
之前执行(当排队管理样式时)。那意味着他们无论如何都会被排队。
使用admin_print_styles
作为挂钩。通过将优先级设为1(add_action()
的最后一个参数),可以确保优先级在打印样式之前得到执行。
add_action( 'admin_print_styles', 'remove_admin_styles', 1 );
function remove_admin_styles()
{
// Dequeue
wp_dequeue_style( 'caldera-forms-admin-icon-styles' );
wp_dequeue_style( 'et-core-admin' );
wp_dequeue_style( 'et-core-portability' );
wp_dequeue_style( 'wf-common-style' );
wp_dequeue_style( 'wf-fedex-style' );
wp_dequeue_style( 'woocommercebulkdiscount-style-admin' );
wp_dequeue_style( 'tm_epo_admin_css' );
wp_dequeue_style( 'tc-font-awesome' );
wp_dequeue_style( 'tm_global_epo_animate_css' );
wp_dequeue_style( 'tm_global_epo_admin_css' );
wp_dequeue_style( 'tm_global_epo_admin_font' );
wp_dequeue_style( 'tm-spectrum' );
wp_dequeue_style( 'tc-font-awesome' );
wp_dequeue_style( 'yoast-seo-admin-global' );
wp_dequeue_style( 'yoast-seo-dismissible' );
wp_dequeue_style( 'et-meta-box-style' );
wp_dequeue_style( 'et-core-version-rollback' );
wp_dequeue_style( 'library-menu-styles' );
wp_dequeue_style( 'woocommerce_admin_menu_styles' );
wp_dequeue_style( 'woocommerce_admin_styles' );
wp_dequeue_style( 'yoast-seo-toggle-switch' );
wp_dequeue_style( 'yoast-seo-admin-css' );
wp_dequeue_style( 'woocommerce-activation' );
wp_dequeue_style( 'dashicons' );
// Deregister
wp_deregister_style( 'caldera-forms-admin-icon-styles' );
wp_deregister_style( 'et-core-admin' );
wp_deregister_style( 'et-core-portability' );
wp_deregister_style( 'wf-common-style' );
wp_deregister_style( 'wf-fedex-style' );
wp_deregister_style( 'woocommercebulkdiscount-style-admin' );
wp_deregister_style( 'tm_epo_admin_css' );
wp_deregister_style( 'tc-font-awesome' );
wp_deregister_style( 'tm_global_epo_animate_css' );
wp_deregister_style( 'tm_global_epo_admin_css' );
wp_deregister_style( 'tm_global_epo_admin_font' );
wp_deregister_style( 'tm-spectrum' );
wp_deregister_style( 'tc-font-awesome' );
wp_deregister_style( 'yoast-seo-admin-global' );
wp_deregister_style( 'yoast-seo-dismissible' );
wp_deregister_style( 'et-meta-box-style' );
wp_deregister_style( 'et-core-version-rollback' );
wp_deregister_style( 'library-menu-styles' );
wp_deregister_style( 'woocommerce_admin_menu_styles' );
wp_deregister_style( 'woocommerce_admin_styles' );
wp_deregister_style( 'yoast-seo-toggle-switch' );
wp_deregister_style( 'yoast-seo-admin-css' );
wp_deregister_style( 'woocommerce-activation' );
wp_deregister_style( 'dashicons' );
}