WordPress 2.8 body_class, automatic_feed_links
Template Tag body_class
The coming WordPress 2.8 provides a new Template Tag, body_class. This function gives the body element different classes, which gives you the possibility to use it effectively with CSS.
<body <?php body_class(); ?>>
Like in the comment area and post classes, the WordPress-Developer get the best out of the database. Here an example if you open a page template “tutorial.php”:
<body class="page-template page-template-tutorial-php logged-in">
All in all, there are following classes available:
- rtl
- home
- blog
- archive
- date
- search
- paged
- attachment
- error404
- single postid-(id)
- attachmentid-(id)
- attachment-(mime-type)
- author
- author-(user_nicename)
- category
- category-(slug)
- tag
- tag-(slug)
- page-parent
- page-child parent-pageid-(id)
- page-template page-template-(template file name)
- search-results
- search-no-results
- logged-in
- paged-(page number)
- single-paged-(page number)
- page-paged-(page number)
- category-paged-(page number)
- tag-paged-(page number)
- date-paged-(page number)
- author-paged-(page number)
- search-paged-(page number)
Template Tag automatic_feed_links
This function is in the function.php of the Default-Theme. automatic_feed_links() enables the automatic output of feed links in the header area of the document. This function is active by default, but you can turn it off, it won’t output any feed links anymore:
automatic_feed_links(false);//no output
automatic_feed_links();//no output
In single view there is the output of feed, comment feed and additionally the post-comment-feed.
The upcoming new version of Thematic Framework For WordPress will provide classes based on the browser, the version of the browser and the os where the page is running.
I think this is really helpful for styling..
@Justin In Justin Tadlocks Hybrid theme that body class based on browser and OS is already built in. you can check it out @ Theme Hybrid.
Nice … this will open up the ability to change the look of nearly everything with CSS only.
Drupal has been using this feature for a long time..I am going take a guess here that wordpress got the idea from Drupal.
Hi there… I really enjoyed the post and have had fun using the body_class() function–successfully–for the ‘home’, ‘single’ and ‘page’ classes. However, I’m trying to figure out how to use the function with “specific WP pages” and for some reason I can’t figure it out. In other words, how can I set up a body class that applies only to particular WP page (e.g. page ID 19)? Any help you can offer would be much appreciated. Thanks.
Best, Chris
Chris, for a page i have the following output from body_class():
page page-id-18 page-parent page-template page-template-default logged-in
So you can use .page-id-18 in your stylesheet.
My site has been compromised and has spam urls inserted into the html on the home page.
I have tried reinstalling, and if I delete the following code from the header theme it just reappears staight back.
Here is the code as it appears before the spam urls in the html
<div style=
here is what i have deleted from the header theme
<body >
Can you please suggest how I solve this as its driving me mad?
This is very useful, makes our blog integrations so much easier. Is there any way to remove any of those ‘reserved’ class names though?
Thanks!