Alister Cameron // Blogologist

Changing the world. One blog(ger) at a time.

WordPress Plugin: ClassyBody v1.1 Update

I have updated my ClassyBody WordPress plugin to v1.1 with the addition of ad-hoc custom CSS classes.

To recap, my ClassyBody plugin adds contextually intelligent CSS classes to your BODY tag, giving the more high-powered designers out there much greater control of the CSS of a given WordPress page. It automatically adds CSS classes telling you whether you’re on a page/post/archive page/error page and so forth. It even uses CSS “datestamps” (month and year) so you can group posts and/or pages together with a common styling based on age, for example.

So, yeah. It’s a powerful little plugin in the hands of a good designer with good CSS skills. People were looking for something like this and it was easy to create as my first ever plugin!

But one thing was missing…

So, I’ve now updated ClassyBody to Version 1.1 with the addition of ad-hoc custom CSS classes which you can add to any page or post via WordPress Custom Fields. All you have to do is create a custom field called “classybody” for every post or page to which you want to provide a custom CSS style definition. To keep things clean, ClassyBody will strip out anything that is not a letter, number or a dash (“-“). You may add multiple “classybody” custom fields, or more likely, space-separated class names in the single custom field.

What would you use this for? Whatever you like! You may have a series of posts that are related, and this is the simplest/best way to provide a CSS definition to tie them together. It’s really limited to your imagination.

A final note for the techies out there: because the opening BODY tag is outside “the loop”, I can’t get around the need for one database call, to go get the required custom field information. Alas… you can’t have power without burning a tiny bit more energy 🙂

wordpress, custom fields, css, stylesheets, web design, html, plugin, wordpress plugins, body tag


Note: Commenter website links are not no-followed, in case
you were wondering... I believe in rewarding commenters!

  1. Alister Cameron
    Posted 12 years, 4 months ago // Permalink

    Forgot to mention in the post…

    If you view the source on this page, you’ll see the “custom-class” CSS attribute in the BODY tag… just to prove it works!

  2. Posted 12 years, 4 months ago // Permalink

    Hey Alister, that’s a great plugin idea! You should take a look at the Worpdress Custom Fields Contest, I’m sure this would be eligible.

    I’m actually trying to think of an idea myself. 🙂

  3. Alister Cameron
    Posted 12 years, 4 months ago // Permalink

    Thanks Hamish… I’ve thought of that, and probably will, except that it’s pretty simple, as use of custom fields is concerned… but it may be worth a go 🙂

  4. Posted 11 years, 8 months ago // Permalink

    The ClassyBody custom field is not working at all. If I have two or more pages with ClassyBody custom field, they all show up on body like this:

  5. Posted 11 years, 8 months ago // Permalink

    I believe it is a problem with WP 2.3

  6. Posted 11 years, 8 months ago // Permalink

    Well, I fixed the bug. I uploaded the fixed file to my server if you want to see what I changed:

    Great plugin, by the way. Helped me a lot.

  7. Palli Svansson
    Posted 11 years, 6 months ago // Permalink

    A great plugin if there were more examples for thickheads like me.
    Could you make an css example for setting a background image for a specific post or page. Let´s say the page and post ID is 109. I’ve tried various things but nothing seems to work. The plugin works though because the header examples you demonstrated are fine on my site.

  8. Miyoung Jeon
    Posted 11 years, 4 months ago // Permalink

    Hi Alister,

    I have a porblme to use the classybody.
    After I changed header.php and check my blog, I got the error:

    <body class=”
    Fatal error: Call to undefined function classybody() in C:\xampp\htdocs\wordpress\wp-content\themes\karma-fruit-10\header.php on line 20

    I don’t know how to fix it.

  9. davido
    Posted 11 years, 1 month ago // Permalink

    hey Alister… This plugin is incredibly useful.
    is Classybody ready for WP 2.5?

  10. Anja
    Posted 11 years ago // Permalink

    I love this plugin and will try to include the body class to all of my future themes. BUT… that will only be possible if someone could put some lines of code in that will find out if the plugin is activated and the function is available.

    If you just put in the code in the body Tag, and do not activate the Plugin, you will get the same error as Miyoung Jeon.

    is there a way to put something like “if function exists… ” in? I am sorry that I am no coder so I can’t do it myself.

    Thanx anyway for the great plugin. If I find a solution, I’ll let you know.

    Greetings from Germany

  11. Anja
    Posted 11 years ago // Permalink

    Well. I’m back already. Sometimes you should take the time and try.
    I don’t know if this is the PERFECT code for my problem (and Miyoung’s ) but it works for me!

    Instead of <body class=””>

    I changed the code to:

    <body class=””>

    Hope this helps anyone besides me 😉
    Thanx again for this plugin!

  12. Posted 11 years ago // Permalink

    Anja, I think your code was cutted. But the solution is this (if that’s was what you wrote): <body class="<?php if (function_exists(‘classybody’)) classybody(); ?>">

  13. Anja
    Posted 11 years ago // Permalink

    Thanx Rafael,
    seems I still have to learn how to comment 😉
    You are of course RIGHT! Thank you for correcting.
    Greetings from Germany

  14. Posted 9 years, 12 months ago // Permalink

    Does anyone have Rafael’s fixed version available? His link is now broken, and I’m experiencing the same problem (classybody pulls classnames from ALL pages in the db, not just the one I’m on).

  15. Posted 9 years, 11 months ago // Permalink

    David, WordPress 2.8 have a better function built in. Just do like this:
    <body >

2 Trackbacks/Pingbacks

  1. [IMG] WordPress Plugin: ClassyBody v1.1 Update 10 minutes ago by alicam at Alister Cameron, Blog Consultant I have updated my ClassyBody WordPress plugin to v1.1 with the addition of ad-hoc custom CSS classes. To recap, my ClassyBody plugin adds contextually intelligent CSS…

  2. […] Version 1.1.20070202 (2 Feb. 2007). Added custom class feature using custom fields for posts and pages. Read this post for details. […]

Post a Comment

Your email is never published nor shared. Required fields are marked *

  • My Posts in Your In-box!

    Enter your email address here for instant updates in your inbox, whenever I post something new.
    Your email address is in safe hands. Relax!
© Copyright 2007 Alister Cameron. All Rights Reserved Theme // Sitemap // RSS