ThemeShaper Forums » Thematic

[closed]

How to add a class to the body tag with a filter?

(4 posts)
  • Started 2 years ago by benfrain.com
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. I'm amending a filter I'd seen Chris had posted elsewhere in the forum: http://forums.themeshaper.com/topic/how-to-add-a-class-to-the-ltbodygt-declaration

    I'm trying to adapt it to do the following:

    1. If the page is a forum (bbpress) page - add the class 'bbforum' to the body
    2. If it isn't a forum page - leave the dynamic classes as they were before

    Here's what I have in functions.php:

    function extend_body_class($c) {
    	if (function_exists('is_bbpress') && is_bbpress()) {
    	$c[] = 'bbForum';
    	return $c;
    	}
    }
    add_filter('thematic_body_class', 'extend_body_class');

    Which works fine on the forum pages, however, on other pages it is truncating the dynamic classes. What do I need to change to stop it doing that????

    Posted 2 years ago #
  2. so close ben, but you need to return $c no matter what. i think this should do it:

    function extend_body_class($c) {
    	if (function_exists('is_bbpress') && is_bbpress()) {
    	   $c[] = 'bbForum';
            }
    	return $c;
    }
    add_filter('thematic_body_class', 'extend_body_class');
    Posted 2 years ago #
  3. Hallelujah and pass the biscuits! Thanks Kathy, you're a gem!

    Posted 2 years ago #
  4. cue the happy trombones!

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.