get_current_screen

How to identify context inside the WordPress dashboard

On wp-hackers, Haluk Karamete asked:

on admin pages, how can I detect that the current admin is dealing with a cpt?

Andrew Nacin answered:

get_current_screen()->post_type.

[But] this will also specify a post type when it’s a taxonomy being edited. To filter that out, ensure that get_current_screen()->base == 'post', which is [true] for edit.php, post-new.php, and post.php (for all post types).

Haluk didn’t elaborate on the cause of the question, but the answer is very good advice for those seeking to conditionally enqueue JS and styles only for specific post types.