我试图删除一些脚本文件添加的wordpress。但是,我编写的代码不起作用。我哪里做错了?你能给我指路吗?
我看了很多消息来源。但我找不到ui的答案。我已经多次使用wp_dequeue_script函数了。但它对Wordpress不起作用。
儿童主题function.php
add_action( 'wp_enqueue_scripts', 'a_remove_some_js');
function a_remove_some_js() {
//wp_dequeue_script( 'jquery-ui-core-js');
//wp_dequeue_script( 'jquery-ui-tooltip-js');
wp_dequeue_script( 'jquery-ui-core');
wp_dequeue_script( 'jquery-ui-tooltip');
}发布于 2022-06-10 20:48:17
相关库是用名为wp_默认设置_脚本的函数注册的。文件位置(用于Wordpress 6.0):.wp-include/script-loader.php删除以删除相关脚本;add函数用于添加新脚本。
/**
* Assigns default styles to $styles object.
*
* Nothing is returned, because the $styles parameter is passed by reference.
* Meaning that whatever object is passed will be updated without having to
* reassign the variable that was passed back to the same value. This saves
* memory.
*
* Adding default styles is not the only task, it also assigns the base_url
* property, the default version, and text direction for the object.
*
* @since 2.6.0
*
* @global array $editor_styles
*
* @param WP_Styles $styles
*/
add_action( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery-ui-core');
}}
发布于 2022-10-02 10:35:07
它是add_action,不是过滤器钩子- @ddisdevelpgelis
您将其作为过滤器挂钩添加到下面的代码中。
add_filter( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery-ui-core');
}
}我对上述代码的更改:
add_action( 'wp_default_scripts', 'remove_js_ui_library' );
function remove_js_ui_library( &$scripts){
if(!is_admin()){
$scripts->remove( 'jquery-ui-core');
}
}查看此链接以获取更多信息- wp_默认设置_脚本
https://wordpress.stackexchange.com/questions/406640
复制相似问题