我面临的奇怪问题是hl_admin_script不会在页脚中加载。但是当我将 $ in_footer 更改为 false
时,它会加载/*
Load Admin Scripts only on custom-post-type post type.
*/
function hl_enqueue_admin() {
global $post;
$screen = get_current_screen();
if ($screen->post_type !== 'custom-post-type') {
return;
}
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-widget');
wp_enqueue_script('jquery-ui-sortable');
wp_enqueue_script('jquery-ui-accordion');
wp_enqueue_style( 'hl_jquery-ui', plugins_url( 'css/hl-jquery-ui.css', __FILE__ ) , array(), '1.0.0', false );
wp_enqueue_script( 'hl_admin_script', plugins_url( '/js/hl_admin_script.js', __FILE__ ) , array('jquery','jquery-ui-core', 'jquery-ui-sortable','jquery-ui-accordion'), '2.0.0', true );
// in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
wp_localize_script( 'hl_admin_script', 'ajax_object',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'post_id' => $post->ID,
));
}
add_action( 'admin_enqueue_scripts', 'hl_enqueue_admin' ,1000 ,0 );