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

So I'm trying to figure out how to properly use the get_current_screen. For learning sake, I'm just popping an alert for a specific page. I've looked at http://www.deluxeblogtips.com/2012/01/get-admin-screen-information.html and the codex on WP_Screen and get_current_screen (hit my max links cause my rep isn't 10 yet)

I thought I was doing this right...but not getting it to work. What I'm hoping for is that when I go to /wp-admin/post-new.php?post_type=product I can do stuff (will be enqueueing a script). Did pretty much a straight copy and changed the post type...but, what am I missing here?

add_action( 'wp_enqueue_scripts', 'rw_enqueue_scripts' );
* Enqueue scripts for 'post' page of 'product' post type only
* @return void

function rw_enqueue_scripts()


$screen = get_current_screen();

// Check screen base and current post type
if ( 'post' === $screen->base && 'product' === $screen->post_type )
    echo "<script type='text/javascript'>alert('worked');</script>


Thanx in advance,


share|improve this question
up vote 3 down vote accepted

wp_enqueue_scripts is only fired on the front end, and not on admin screens. For loading scripts admin side, you'll want the hook admin_enqueue_scripts.

Passed as an optional argument is the page hook. (Examples include edit.php, for the admin edit page (which lists pages/posts/ cpt posts), post.php when editing a post/ custom post type and post-new.php when creating a new one).

$screen = get_current_screen(); is also available to you, so you can restrict by post type. E.g.:

add_action( 'admin_enqueue_scripts', 'rw_enqueue_scripts' ,10,1);

function rw_enqueue_scripts($hook){

    $screen = get_current_screen();

    // Check screen hook and current post type
    if ( 'post.php' == $hook && 'product' == $screen->post_type ){
        //Load scripts
share|improve this answer
bloody hell...I knew that, "admin_enqueue_scripts" grrr it's always the little things...but I didn't know about passing the hook...awesome! Working now! Thanks Stephen. – Brian Thornton Apr 22 '12 at 20:32

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.