X

Add custom body_class to all post and pages

This is similar to another body_class post I made however I had a few emails asking about just adding a specific class to the body on every page. Adding this snippet to the functions.php of your wordpress theme will let you add specific classes to wordpress body_class function. Don't forget to add <?php body_class(); ?> to the body tag within header.php.



Code Snippet:


add_filter('body_class','add_body_classes');
function add_body_classes($classes) {
$classes[] = 'my-class-one';
$classes[] = 'my-class-two';
$classes[] = 'my-class-three';
return $classes;
}


Code Snippet:


<?php body_class(); ?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!