Title: Add URL Slugs as Body Classes
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-url-slugs-as-body-classes.svg)

# Add URL Slugs as Body Classes

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

[下载](https://downloads.wordpress.org/plugin/add-url-slugs-as-body-classes.1.3.zip)

 * [详情](https://cn.wordpress.org/plugins/add-url-slugs-as-body-classes/#description)
 * [评价](https://cn.wordpress.org/plugins/add-url-slugs-as-body-classes/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/add-url-slugs-as-body-classes/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/add-url-slugs-as-body-classes/#developers)

 [支持](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/)

## 描述

This plug-in takes the URL, chops it into pieces, and adds each “piece” as an additional

class to the `body` tag.

Meaning, if your page’s URL is:
 http://www.example.com/2012/02/24/wordpress-plugin-
add-url-slugs-as-body-classes/ Your page’s `body` tag would have at least these 
classes: 2012 02 24 wordpress-plugin-add-url-slugs-as-body-classess

It gets much stronger when you start thinking about Categories or nested Pages:

http://www.example.com/category/wordpress/ which would add: category wordpress while:
http://www.example.com/movies/star-trek/wrath-of-khan/ would add: movies star-trek
wrath-of-khan

This allows you to very easily add custom CSS and/or JS to these pages based on 
these new CSS classes.

Please let me know if you have any questions/suggestions/thoughts,
 Atg http://aarontgrogg.
com/ aarontgrogg@gmail.com

## 安装

 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 to amaze your friends and befuddle your enemies…

## 常见问题

  What does this do, exactly?

 * Additional CSS classes are added to the HTML `body` tag so you can easily add
   custom CSS and/or JS to Posts or
    Pages. Basically anything that appears in the
   URL after your domain name, will be split on the “/”, then pushed back together
   separated by spaces in the HTML’s `body` tag.

  What classes?

 * Say you created a Post that could be found at the following URL:
    http://www.
   example.com/2012/02/24/wordpress-plugin-add-url-slugs-as-body-classes/ That page’s`
   body` tag would have at least these classes: 2012 02 24 wordpress-plugin-add-
   url-slugs-as-body-classess
 * It gets much stronger when you start thinking about Categories or nested Pages,
   because a Category page like:
    http://www.example.com/category/wordpress/ get
   these additional CSS classes: category wordpress This would allow you to add 
   custom CSS and/or JS to all Category pages, or even _just_ the WordPress Category
   page!
 * Or a nested Page that could be found at this URL:
    http://www.example.com/movies/
   star-trek/wrath-of-khan/ would get these additional CSS classes: movies star-
   trek wrath-of-khan So you could add custom CSS _just_ for your Movies pages, 
   other custom CSS for _just_ the Star Trek Movies pages, and still more custom
   CSS for _just_ the Wrath of Khan Star Trek Movie page.

  Why would I want to do this?

 * Really only if you used some custom CSS or JS to some specific webpages. You 
   could add custom background images,
    use different fonts, add sound effects, 
   add different JS libraries, the list is limited only by your needs, really.

## 评价

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

### 󠀁[Love this plugin](https://wordpress.org/support/topic/love-this-plugin-922/)󠁿

 [websitedeptuk](https://profiles.wordpress.org/websitedeptuk/) 2020 年 6 月 18 
日

One of the most consistently useful plugins there has been over the years!

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

### 󠀁[Works beautifully!](https://wordpress.org/support/topic/works-beautifully-6/)󠁿

 [Andrew](https://profiles.wordpress.org/andrewjohnstrong/) 2016 年 11 月 15 日

Works beautifully!

 [ 阅读所有5条评价 ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/)

## 贡献者及开发者

「Add URL Slugs as Body Classes」是开源软件。 以下人员对此插件做出了贡献。

贡献者

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

[帮助将「Add URL Slugs as Body Classes」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/add-url-slugs-as-body-classes)

### 对开发感兴趣吗?

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

## 更新日志

#### 1.3

2015-05-15:
 * Tested & verified in WP 4.2.2, and added a few FAQs

#### 1.1

2013-01-11:
 * Tested & verified in WP 3.5

#### 1.0

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

## 额外信息

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

## 评级

 4.8 星（最高 5 星）。

 *  [  4 条 5 星评价     ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/?filter=5)
 *  [  1 条 4 星评价     ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/?filter=4)
 *  [  0 条 3 星评价     ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/?filter=3)
 *  [  0 条 2 星评价     ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/?filter=2)
 *  [  0 条 1 星评价     ](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/?filter=1)

[您的评价](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/reviews/)

## 贡献者

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

## 支持

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

 [查看支持论坛](https://wordpress.org/support/plugin/add-url-slugs-as-body-classes/)