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 );
  • 1
    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

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
  • 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:)

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.