如果您想以显示帖子编辑器的管理页面为目标,那么可能需要挂接到两个位置,无论是脚本还是样式。
上面两个用于脚本,下面两个用于样式。
// Script action for the post new page    
add_action( \'admin_print_scripts-post-new.php\', \'example_callback\' );
// Script action for the post editting page    
add_action( \'admin_print_scripts-post.php\', \'example_callback\' );
// Style action for the post new page    
add_action( \'admin_print_styles-post-new.php\', \'example_callback\' );
// Style action for the post editting page 
add_action( \'admin_print_styles-post.php\', \'example_callback\' );
 如果您想针对特定的帖子类型,只需全局
$post_type 在回调函数中,如下所示。。
function example_callback() {
    global $post_type;
    // If not the desired post type bail here.
    if( \'your-type\' != $post_type )
        return;
    // Else we reach here and do the enqueue / or whatever
}
 如果您将脚本(而不是样式)排队,那么前面运行的一个钩子称为
admin_enqueue_scripts 它作为第一个参数传递到钩子上,因此对于脚本也可以这样做。。(如果你在
admin_enqueue_scripts 而不是两个
admin_print_scripts 上述操作)。
function example_callback( $hook ) {
    global $post_type;
    // If not one of the desired pages bail here.
    if( !in_array( $hook, array( \'post-new.php\', \'post.php\' ) ) )
        return;
    // If not the desired post type bail here.
    if( \'your-type\' != $post_type )
        return;
    // Else we reach here and do the enqueue / or whatever
}
 这些挂钩正是针对这种类型的东西而存在的,您不需要尽早启动这些东西
admin_init 除非您的特定用例要求。如果您不确定,很可能不需要那么早启动代码。