diTii.com Digital News Hub

Sign up with your email address to be the first to know about latest news and more.

I agree to have my personal information transfered to MailChimp (more information)


WordPress: ClassyBody Plugin

ClassyBody plugin adds contextually-relevant classes to the body tag of your WordPress blog, and gives you the power to control the look and feel of your blog using CSS. You could make your single pages look different or a single post have a festive theme with modification of the CSS.

In other words —”it change the appearance of any page element, purely in CSS, based on what kind of webpage Wordpress blog is displaying. Along the lines of the “is_functions()”, it let you know when you’re on the homepage, a search results page, a single post, etc. Then you can change the header image, or the page background, or perhaps change the dimensions of the sidebar, or whatever…”

ClassyBody v1.0 conditionally adds the following classes to your Body tag:

homeYour blog’s homepage.
pageAny static page.
page-[ID]Any static page (eg. page-4).
postAn individual (single) post.
post-[ID]An individual (single) post (eg. post-71).
categoryA category archive page.
cat-[ID]A category archive page (eg. cat-12).
archiveA dated archive page.
[Month] [year]A given month’s archives or a single post (eg. March 2006).
searchA search (results) page.
errorA 404 (”page not found”) error page.


The following examples are very simple and assume the naming convention of the WordPress Default theme’s CSS.

Winter-themed posts. Want all the posts you wrote in Winter to automatically have, say, a snowy-background image? Try something like this (remembering to create and upload the image in question!):

/* a snow theme for winter posts */
body.December, body.January, body.February {
   background-image: url(’images/snowy-background.jpg’);

Of course, if you’re Down Under like me, change the months accordingly.

Different header images. Want to have a special header image for each of the different sections of your blog? Try something like this:

/* the homepage */
body.home #header {
   background-image: url(’images/home-header.jpg’);

/* static pages */
body.page #header {
   background-image: url(’images/page-header.jpg’);

/* individual posts */
body.post #header {
   background-image: url(’images/post-header.jpg’);

/* category archive pages */
body.category #header {
   background-image: url(’images/category-header.jpg’);

/* dated archive pages */
body.archive #header {
   background-image: url(’images/archive-header.jpg’);

/* search (results) pages */
body.search #header {
   background-image: url(’images/search-header.jpg’);

/* 404 error pages */
body.error #header {
   background-image: url(’images/error-header.jpg’);

Customise a specific category, post or page! You may not want to, but ClassyBody gives you the power to do it. For every category archive listing, and for every individual post, the ID is displayed as a class, in the form cat-[ID], post-[ID] or page-[ID]. This means you can change the appearance of any HTML element on any specific post, page or category listing. Just add the specific customisations to your CSS in the right places.


This is a plain vanilla plugin and installs in the normal way:

  1. Download ClassyBody, and rename file from .txt to .php.
  2. Upload the file to wp-content/plugins/ folder.
  3. Goto WordPress Admin, and activate the plugin from the plugins page.
  4. Replace the opening Body tag in your active theme’s header.php file with:
    <body class="<?php classybody(); ?>">

Alister’s Blog

WordPress, ClassyBody Plugin

Share This Story, Choose Your Platform!

Get Latest News

Subscribe to Digital News Hub

Get our daily newsletter about the latest news in the industry.
First Name
Last Name
Email address
Secure and Spam free...