我使用以下代码将管理脚本出列:
add_action('admin_enqueue_scripts', 'remove_admin_script', 100);
function remove_admin_script() {
wp_dequeue_script('layers-admin');
}
此脚本返回页面上所有脚本的句柄列表:
function wpa54064_inspect_scripts() {
global $wp_scripts;
foreach( $wp_scripts->queue as $handle ) :
echo $handle . ' | ';
endforeach;
}
add_action( 'wp_print_scripts', 'wpa54064_inspect_scripts' );
当我将我的脚本出列时,我可以从我的句柄列表中看到它不再存在,但是,在我的源代码中它仍然显示。
有谁能告诉我为什么我的剧本没有删除?
以下是从插件中调用脚本的方法,我试图将其从以下位置删除:
add_action( 'customize_controls_print_footer_scripts' , 'layers_admin_scripts' );
add_action( 'admin_enqueue_scripts' , 'layers_admin_scripts' );
以下是主题中的整个脚本,它将我正在尝试删除的脚本排入队列(admin.js)
if( ! function_exists( 'layers_admin_scripts' ) ) {
function layers_admin_scripts(){
global $pagenow, $wp_customize;
wp_enqueue_style(
LAYERS_THEME_SLUG . '-tip-tip' ,
get_template_directory_uri() . '/core/assets/tipTip.css',
array(),
LAYERS_VERSION
); // Tip-Tip CSS
wp_enqueue_style(
LAYERS_THEME_SLUG . '-admin-font-awesome',
get_template_directory_uri() . '/core/assets/font-awesome.min.css',
array(),
LAYERS_VERSION
); // Inline Editor
wp_enqueue_style(
LAYERS_THEME_SLUG . '-admin',
get_template_directory_uri() . '/core/assets/admin.css',
array(),
LAYERS_VERSION
); // Admin CSS
wp_enqueue_style(
LAYERS_THEME_SLUG . '-admin-editor',
get_template_directory_uri() . '/core/assets/editor.css',
array(),
LAYERS_VERSION
); // Inline Editor
wp_enqueue_script(
LAYERS_THEME_SLUG . '-tip-tip' ,
get_template_directory_uri() . '/core/assets/jquery.tipTip.minified.js',
array(
'jquery',
),
LAYERS_VERSION,
true
); // Tip-Tip JS
wp_enqueue_script(
LAYERS_THEME_SLUG . '-admin-editor' ,
get_template_directory_uri() . '/core/assets/editor.min.js' ,
array( 'jquery' ),
LAYERS_VERSION,
true
); // Inline Editor
wp_enqueue_script(
LAYERS_THEME_SLUG . '-admin-migrator' ,
get_template_directory_uri() . '/core/assets/migrator.js' ,
array(
'media-upload'
),
LAYERS_VERSION,
true
);
wp_enqueue_script(
LAYERS_THEME_SLUG . '-media-views' ,
get_template_directory_uri() . '/core/assets/media-views.js',
array(
'media-views'
),
LAYERS_VERSION
); // Discover More Photos
wp_localize_script(
LAYERS_THEME_SLUG . '-admin-migrator',
'migratori18n',
array(
'loading_message' => __( 'Be patient while we import the widget data and images.' , 'layerswp' ),
'complete_message' => __( 'Import Complete' , 'layerswp' ),
'importing_message' => __( 'Importing Your Content' , 'layerswp' ),
'duplicate_complete_message' => __( 'Edit Your New Page' , 'layerswp' )
)
);// Migrator// Localize Scripts
wp_localize_script(
LAYERS_THEME_SLUG . '-admin-migrator',
"layers_migrator_params",
array(
'duplicate_layout_nonce' => wp_create_nonce( 'layers-migrator-duplicate' ),
'import_layout_nonce' => wp_create_nonce( 'layers-migrator-import' ),
'preset_layout_nonce' => wp_create_nonce( 'layers-migrator-preset-layouts' ),
)
);
// Onboarding Process
wp_enqueue_script(
LAYERS_THEME_SLUG . '-admin-onboarding' ,
get_template_directory_uri() . '/core/assets/onboarding.js',
array(
'jquery'
),
LAYERS_VERSION,
true
); // Onboarding JS
wp_localize_script(
LAYERS_THEME_SLUG . '-admin-onboarding' ,
"layers_onboarding_params",
array(
'preset_layout_nonce' => wp_create_nonce( 'layers-migrator-preset-layouts' ),
'update_option_nonce' => wp_create_nonce( 'layers-onboarding-update-options' ),
'set_theme_mod_nonce' => wp_create_nonce( 'layers-onboarding-set-theme-mods' ),
)
); // Onboarding ajax parameters
wp_localize_script(
LAYERS_THEME_SLUG . '-admin-onboarding' ,
'onboardingi18n',
array(
'step_saving_message' => __( 'Saving...' , 'layerswp' ),
'step_done_message' => __( 'Done!' , 'layerswp' )
)
); // Onboarding localization
wp_enqueue_script(
LAYERS_THEME_SLUG . '-admin' ,
get_template_directory_uri() . '/core/assets/admin.js',
array(
'jquery',
'jquery-ui-sortable',
'wp-color-picker',
),
LAYERS_VERSION,
true
); // Admin JS
wp_localize_script(
LAYERS_THEME_SLUG . '-admin' ,
"layers_admin_params",
array(
'backup_pages_nonce' => wp_create_nonce( 'layers-backup-pages' ),
'backup_pages_success_message' => __('Your pages have been successfully backed up!', 'layerswp' )
)
); // Onboarding ajax parameters
wp_enqueue_media();
}
}
add_action( 'customize_controls_print_footer_scripts' , 'layers_admin_scripts' );
add_action( 'admin_enqueue_scripts' , 'layers_admin_scripts' );
或者这里是Git上整个文件的链接: https://github.com/Obox/layerswp/blob/master/functions.php
文件是从名为layers的主题调用的,只在wordpress自定义程序中调用
答案 0 :(得分:0)
add_action( 'admin_enqueue_scripts', 'remove_admin_script', 100 );
add_action( 'customize_controls_print_footer_scripts' , 'remove_admin_script', 100 );
比在wp_print_scripts之后运行函数更正确。