0

I am using this code to load a stylesheet in the admin, but only on post.php related pages:

function my_enqueue_for_post_pages_only($hook) {
    if( 'post.php' != $hook )
        return;
    wp_register_style( 'custom_wp_admin_css_for_post_pages_only', get_template_directory_uri() . '/style_admin-post.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css_for_post_pages_only' );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue_for_post_pages_only' );

But I am needing to be more specific with where this stylesheet loads...I would like to enqueue it only on 3 post.php edits screens:

  • post.php?post=7&action=edit
  • post.php?post=10&action=edit
  • post.php?post=18&action=edit

Changing line 2 to this does not work:

if( 'post.php?post=7&action=edit' != $hook )

Is it even possible to be this specific with the admin_enqueue_scripts hook?

1

The $hook_suffix global (copy of which you are getting passed to the hook) doesn't go into such detail.

However there is plenty more of context to check. In modern WP versions bulk of it is via get_current_screen() which returns WP_Screen object with plenty of stuff (in this case you would want to check id and post_type properties likely).

As for post's ID — get_the_ID() should work perfectly fine in that context.

  • Thank you for your response. I had actually been looking in to get_current_screen along with admin_enqueue_script, but all the examples and articles for get_current_screen were very confusing (I am a PHP novice). I have asked another question, regarding get_current_screen, perhaps you could help there too?: wordpress.stackexchange.com/questions/159476/… – codeview Aug 28 '14 at 21:04

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.