sandywp / plugins / add-url-slugs-as-body-classes
Add URL Slugs as Body Classes
Add URL Slugs to body Class
Ready in seconds.
v1.3 700+ installs WP 3.1+
About this plugin
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/
[email protected]
Questions
- What does this do, exactly?
- Additional CSS classes are added to the HTML
bodytag 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’sbodytag.
- Additional CSS classes are added to the HTML
- 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’sbodytag would have at least these classes:
2012 02 24 wordpress-plugin-add-url-slugs-as-body-classessIt 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.
- Really only if you used some custom CSS or JS to some specific webpages. You could add custom background images,
sandywp / also on the shelf
Try another plugin
5.0 · 200K+ installs
Easy add site-wide, category and article specific custom code before the closing </head> and </body>, or after…
5.0 · 10K+ installs
A plain simple plugin which allows you to add a custom CSS class the HTML body tag.
4.1 · 1K+ installs
Easily insert custom HTML, CSS, and JavaScript into your WordPress site's header, body, and footer without modifying theme files.
Spin up a real WordPress site in seconds.
Test plugins, build a demo, hand a client a link — then squash it and start again. No local setup, no Docker.