Add Custom Post Type Slugs to Admin `<body>` Class
|Author:||Aaron T. Grogg (profile at wordpress.org)|
|WordPress version required:||3.1|
|WordPress version tested:||4.2.2|
|Added to WordPress repository:||25-02-2012|
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
|Total downloads:||1 694|
Click to start download
When in Admin mode, this plug-in adds classes to the
<body> tag to let
your CSS know where you are.
For example, if you are viewing the list of all your Posts, you would get this additional class:
And, when you are editing a Post, something like this:
Alternatively, for custom posts, for example "movie", you would see either:
This allows you to write custom CSS and JS to interact with these varying edit pages within WP.
Please let me know if you have any questions/suggestions/thoughts, Atg
What does this do, exactly?
- Additional CSS classes are added to the HTML
bodytag when certain pages load in Admin mode
- If you are in WP Admin, if you click Posts, you will see a list of all your Posts, and the CSS class
will be added to the HTML
bodytag. If you click a specific Post, you will enter the edit page for that Post,
and the CSS class
edit-page-postwill be added to the HTML
bodytag. Note the difference between the two:
Similarly, if you click Pages, the same thing as above will happen, except the word
postwill be replaced with
pagein each of the CSS classes. Futher, if you have custom post types, the word
postwill be replaced
with whatever your custom post type is, so a custom post type called “Movies” will results in the following CSS classes
Why would I want to do this?
- Really only if you used some custom CSS or JS in your WP Admin. You could color the List or Edit headers or
backgrounds differently, add custom validation to some fields, etc. Maybe when you are viewing the list of Posts,
you want to see red column and field headers, blue when viewing Pages, and green when viewing Movies, and for the
Movies Edit page, you have a custom field that you want to validate as some specific format, like a date or number,
you could add custom JS just for that page, all based on these new classes on the HTML
* Tested in 4.2.2, plus added a few FAQs to better explain what this plugin does and why it might be useful
* Slight mod to make this only run in admin pages, and makes sure it is a posts list page
* Well, this is the first version, so… here it is!