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.

WordPress 2.8 Feed

Comments are closed.


  1. Danny

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

  2. The Frosty @WPCult

    @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.

  3. Goedkope

    Nice … this will open up the ability to change the look of nearly everything with CSS only.

  4. Matthew Hunt

    Drupal has been using this feature for a long time..I am going take a guess here that wordpress got the idea from Drupal.

  5. Chris

    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

  6. Michael

    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.

  7. gilly

    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?

  8. Osborne Brook

    This is very useful, makes our blog integrations so much easier. Is there any way to remove any of those ‘reserved’ class names though?


9 pingbacks

  1. Saturday’s short news&links | Ionut Staicu - Webdeveloper Blog
  2. WordPress News Summary: WordCamps, WordPress Meetups, WordPress PowerPoint, FeedBurner and Flash Warnings « Lorelle on WordPress
  3. Wordpress 2.8 para Abril de 2009 | aNieto2K
  4. WordPress News: WordPress 2.8, Summer of Code, PodPress Returning, iPhone Update | The Blog Herald
  5. WordPress News: Widget API, Bye-Bye Kubrick, Query_Posts Plugin, and Template Tag Plugin | The Blog Herald
  6. Neue Funktion body_class() in WordPress 2.8 | webdemar.com
  7. La funzione body_class() di Wordpress 2.8 - TomStardust.com
  8. Adding Classes to body_class() in WordPress » wpCanyon
  9. How to Style Individual Wordpress Posts in Seconds