这个对我来说很有用,包括customsubmenu页面上的脚本:
add_action(\'admin_menu\', \'register_my_custom_submenu_pages\');
function register_my_custom_submenu_pages() {
$email_menu = add_submenu_page( \'edit.php?post_type=events\', \'Email Users\', \'Email Users\', \'edit_others_posts\', \'email\', \'email_callback\' );
add_action( \'admin_print_styles-\' . $email_menu, \'email_custom_css\' );
add_action( \'admin_print_scripts-\' . $email_menu, \'email_custom_js\' );
}
function email_callback() {
echo \'<div class="wrap">\';
echo \'<h2>\'.get_admin_page_title().\'</h2>\';
include get_stylesheet_directory() . \'/admin/email.php\';
echo \'</div>\';
}
function email_custom_css()
{
wp_enqueue_style( \'chosen\',get_stylesheet_directory_uri().\'/js/chosen/chosen.min.css\' );
};
function email_custom_js()
{
wp_enqueue_script( \'chosen\', get_stylesheet_directory_uri().\'/js/chosen/chosen.jquery.min.js\', array(\'jquery\'));
};
速记这可以翻译为:
add_action( \'admin_print_styles-post.php\', \'custom_css_load\' );
add_action( \'admin_print_styles-post-new.php\', \'custom_css_load\' );
add_action( \'admin_print_scripts-post.php\', \'custom_js_load\' );
add_action( \'admin_print_scripts-post-new.php\', \'custom_js_load\' );
function custom_css_load()
{
wp_enqueue_style( \'my_styles\', plugins_url( \'/css/my_plugin.css\', __FILE__ ) );
};
function custom_js_load()
{
wp_enqueue_script( \'my_scripts\', plugins_url( \'/js/my_plugin.js\', __FILE__ ), array(\'jquery\'));
};
如果js代码依赖于jQuery,不要忘记在jQuery之后加载。
我不能测试这个,所以请随意处理:)