WordPress.org

Plugin Directory

Add Custom Post Type Slugs to Admin Body Class

Add Custom Post Type Slugs to Admin `<body>` Class

What does this do, exactly?

  • Additional CSS classes are added to the HTML body tag when certain pages load in Admin mode

What classes?

  • If you are in WP Admin, if you click Posts, you will see a list of all your Posts, and the CSS class edit-list-post will be added to the HTML body tag. If you click a specific Post, you will enter the edit page for that Post, and the CSS class edit-page-post will be added to the HTML body tag. Note the difference between the two: edit-list-post vs. edit-page-post, list vs. page Similarly, if you click Pages, the same thing as above will happen, except the word post will be replaced with the word page in each of the CSS classes. Futher, if you have custom post types, the word post will be replaced with whatever your custom post type is, so a custom post type called "Movies" will results in the following CSS classes being added: edit-list-movie vs. edit-page-movie

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 body tag.

Requires: 3.1 or higher
Compatible up to: 4.2.2
Last Updated: 2015-5-15
Active Installs: 10+

Ratings

0 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

100,1,1