The Thesis body class filter allows you to add classes to the <body> tag in order to customize posts, pages, or groups of posts and pages on your website.
I’ve written about this a couple of times before, but I’ve taken it a step further here.
The following function adds a variety of classes to the <body> tag while keeping the “custom” class intact and accommodating Thesis post and page custom classes which are set on each respective post/page edit page.
function big_body_classes() {
// Ensure the "custom" class remains
$classes[] = 'custom';
// Add the body_class() function
$bodyclasses = get_body_class();
foreach ($bodyclasses as $bodyclass) {
$classes[] .= $bodyclass;
}
// Accommodate Thesis post classes
if(is_page() || is_single()) {
global $post;
$custom_slug = get_post_meta($post->ID, 'thesis_slug', true);
$deprecated_custom_slug = get_post_meta($post->ID, thesis_get_custom_field_key('slug'), true);
if ($custom_slug) {
$classes[] = $custom_slug;
}
elseif ($deprecated_custom_slug) {
$classes[] = $deprecated_custom_slug;
}
}
return $classes;
}
add_filter('thesis_body_classes', 'big_body_classes');
Liked this post? Get free updates via RSS when we post or
{ 3 comments… read them below or add one }
Hey Adam! I appreciate the follow-up. I’ve been trying to figure this out for months. It works beautifully.
No problem man!
Adam, pardon for the unrelated question. How do I include the same social bookmarking that you use here which is located right after the Header?
BTW, thanks for all the useful tips here. Nice job.