0

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

/wordpress/wp-admin/post-new.php?post_type=slideshow

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_enqueue_script('plupload-all');

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

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

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
3

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
0

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

add_submenu_page('edit.php?post_type=slideshow','page_title','menu_title','capability','menu_slug','function_example');

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.