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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">