WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How should I write if condition to display specific code only when I enter this page:


This is what i was trying to get ;) Thanks to Krzysiek!

function plu_admin_enqueue($hook) {
  $screen = get_current_screen();

if ( 'post.php' == $hook && $screen->post_type == 'slideshow' ) {

      wp_register_script('cplupload', get_template_directory_uri() . '/js/cplupload.js', array('jquery'));

      wp_register_style('cplupload', get_template_directory_uri() . '/css/cplupload.css');

add_action( 'admin_enqueue_scripts', 'plu_admin_enqueue', 10 );
share|improve this question
What code? What are you trying to accomplish? – s_ha_dum Nov 25 '13 at 6:00
@s_ha_dum I think it's clear. He wants to detect if he's on that screen. – Krzysiek Dróżdż Nov 25 '13 at 7:45
@KrzysiekDróżdż : yes, but why? There are numerous obscure hooks on the backend that might work, if I knew exactly what the project was. – s_ha_dum Nov 25 '13 at 15:19
up vote 3 down vote accepted

I would use get_current_screen(); to do this. It returns a WP_Screen object.

You should remember that this function will return NULL if it's called before admin_init action.

In your case it should look like this:

$screen = get_current_screen();

if ( $screen && $screen->action == 'add'
    && $screen->base == 'post' && $screen->post_type == 'slideshow' ) {
    // do your stuff
share|improve this answer
Thanks @KrzysiekDróżdż - I'd love to learn my weak points. :) – Mayeenul Islam Nov 25 '13 at 6:39

I believe you want to show a sub menu to the custom post types use the add_submenu_page for this.

Here is the example for your code


function function_example ()
//here you put your code in order to apper in the sub menu


Hope this will help:)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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