我使用conditional函数is_singular($my_post_type) 在我的插件里面,非常方便。问题是它在后端不起作用。
是否有一种在前端工作的替代方案&;后端?谢谢
我使用conditional函数is_singular($my_post_type) 在我的插件里面,非常方便。问题是它在后端不起作用。
是否有一种在前端工作的替代方案&;后端?谢谢
我现在使用的是:
function custom_singular_backend(){
$screen = get_current_screen();
if ( ( $screen->base == \'post\' ) && ( $screen->post_type == POSTTYPE ) ){
//...
}
}
add_action( \'current_screen\',\'custom_singular_backend\');
如果您有条件地想为您的帖子类型加载任何脚本,那么下面的内容可能会很有用。
function my_enqueue($hook) {
global $current_screen;
/* Check if the post being added/edited is a Custom Post Type which you want */
if ( ( \'post.php\' == $hook || \'post-new.php\' == $hook ) && \'hire\' == $current_screen->post_type )
wp_enqueue_script( \'my_custom_script\', plugin_dir_url( __FILE__ ) . \'/js/myscript.js\' );
}
add_action( \'admin_enqueue_scripts\', \'my_enqueue\' );
没有。没有等效于is_singular()
对于后端页面,可能是因为后端没有与“singuler”页面等效的页面。你没有说你想在这里实现什么,但我猜你可能想利用admin_head-$hook_suffix
射入的钩子admin-header.php
122 /**
123 * Fires in head section for a specific admin page.
124 *
125 * The dynamic portion of the hook, `$hook_suffix`, refers to the hook suffix
126 * for the admin page.
127 *
128 * @since 2.1.0
129 */
130 do_action( "admin_head-$hook_suffix" );