Title: Add Custom Post Type Slugs to Admin Body Class
Author: Aaron T. Grogg
Published: <strong>2012 年 2 月 25 日</strong>
Last modified: 2015 年 5 月 15 日

---

搜索插件

**该插件尚未通过WordPress的最新3个主要版本进行测试**。 当与较新版本的WordPress一起
使用时，可能不再受到维护或支持，并且可能会存在兼容性问题。

![](https://s.w.org/plugins/geopattern-icon/add-custom-post-type-slugs-to-admin-
body-class.svg)

# Add Custom Post Type Slugs to Admin Body Class

 作者：[Aaron T. Grogg](https://profiles.wordpress.org/aarontgrogg/)

[下载](https://downloads.wordpress.org/plugin/add-custom-post-type-slugs-to-admin-body-class.1.3.zip)

 * [详情](https://cn.wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/#description)
 * [评价](https://cn.wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/#developers)

 [支持](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/)

## 描述

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:
 edit-list-post And, when you are editing a Post, something like this: edit-
page-post

Alternatively, for custom posts, for example “movie”, you would see either:
 edit-
list-movie or: edit-page-movie

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

## 安装

 1. Download the ZIP
 2. Unzip the ZIP
 3. Copy/paste the unzipped files into your WP plug-in directory (`/wp-content/plugins/`)
 4. From within WP’s Plugin Admin panel, Activate the plug-in
 5. Write some wicked CSS and JS to amaze your friends and befuddle your enemies!

## 常见问题

  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.

## 评价

![](https://secure.gravatar.com/avatar/cc0b0a6040968502ed90c0c75bdb8c9b25dd01b7bb75ba48730d35e70a8ad61a?
s=60&d=retro&r=g)

### 󠀁[works on WP 5.0.3](https://wordpress.org/support/topic/works-on-wp-5-0-3/)󠁿

 [Phll](https://profiles.wordpress.org/phll/) 2019 年 1 月 14 日

Wow this is exactly what I needed! Awesome! Thank you so much

 [ 阅读所有1条评价 ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/)

## 贡献者及开发者

「Add Custom Post Type Slugs to Admin Body Class」是开源软件。 以下人员对此插件做出
了贡献。

贡献者

 *   [ Aaron T. Grogg ](https://profiles.wordpress.org/aarontgrogg/)

[帮助将「Add Custom Post Type Slugs to Admin Body Class」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/add-custom-post-type-slugs-to-admin-body-class)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/add-custom-post-type-slugs-to-admin-body-class/)，
查看[SVN仓库](https://plugins.svn.wordpress.org/add-custom-post-type-slugs-to-admin-body-class/)，
或通过[RSS](https://plugins.trac.wordpress.org/log/add-custom-post-type-slugs-to-admin-body-class/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/add-custom-post-type-slugs-to-admin-body-class/)。

## 更新日志

#### 1.3

2015-05-15:
 * Tested in 4.2.2, plus added a few FAQs to better explain what this
plugin does and why it might be useful

#### 1.2

2015-03-13:
 * Slight mod to make this only run in admin pages, and makes sure it
is a posts list page

#### 1.0

2012-02-24:
 * Well, this is the first version, so… here it is!

## 额外信息

 *  版本 **1.3**
 *  最后更新：**12 年前**
 *  活跃安装数量 **10+**
 *  WordPress 版本 ** 3.1 或更高版本 **
 *  已测试的最高版本为 **4.2.39**
 *  语言
 * [English (US)](https://wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/)
 * 标签
 * [admin](https://cn.wordpress.org/plugins/tags/admin/)[body](https://cn.wordpress.org/plugins/tags/body/)
 *  [高级视图](https://cn.wordpress.org/plugins/add-custom-post-type-slugs-to-admin-body-class/advanced/)

## 评级

 5 星（最高 5 星）。

 *  [  1 条 5 星评价     ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/?filter=5)
 *  [  0 条 4 星评价     ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/?filter=4)
 *  [  0 条 3 星评价     ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/?filter=3)
 *  [  0 条 2 星评价     ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/?filter=2)
 *  [  0 条 1 星评价     ](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/?filter=1)

[您的评价](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/reviews/)

## 贡献者

 *   [ Aaron T. Grogg ](https://profiles.wordpress.org/aarontgrogg/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/add-custom-post-type-slugs-to-admin-body-class/)