2

I use the conditonal function is_singular($my_post_type) inside my plugin and it is very convenient. The problem is that is doesn't work backend.

Is there an alternative that works frontend & backend ? Thanks !

1
  • I guess there won't be any custom post type will be rendered in backend. So why do you need that in backend?
    – WPTC-Troop
    Dec 31 '15 at 12:33
4

Here's what I use now:

function custom_singular_backend(){
    $screen = get_current_screen();

    if ( ( $screen->base == 'post' ) && ( $screen->post_type == POSTTYPE )  ){
        //...
    }
}
add_action( 'current_screen','custom_singular_backend');
1

If you conditionally want to load any scripts for your post type then following may be useful.

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' );
0

No. There is no equivalent to is_singular() for backend pages, possible because there are no equivalents to "singuler" pages on the backend. You don't say what you want to achieve here, but I'd guess you probably want to exploit the admin_head-$hook_suffix hooks that fire in 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" );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.