How Add custom parameters into the body_class() function ?

When creating a website on WordPress, it can be really useful to be able to add one (or more) custom parameter into the body_class() function. Here is a function I use very often when building sites for my clients.

Copy and paste this code in your themes function.php files

function custom_body_class($classes){
		$myvar = "myparam";
	} else {
		$myvar = "anotherparam";
	global $post;
	array_push($classes, $myvar);
	return $classes;
add_filter('body_class', 'custom_body_class');

Save file.
Enjoy Code!

12 Replies to “How Add custom parameters into the body_class() function ?”

  1. Hey There. I discovered your weblog using msn. That is a really
    neatly written article. I will be sure to bookmark it and come back to read extra of your useful info.
    Thank you for the post. I will definitely return.

  2. I do agree with all of the concepts you’ve introduced in your post.
    They are very convincing and can certainly work. Nonetheless, the posts
    are too brief for newbies. May you please lengthen them a little from next time?
    Thanks for the post.

Leave a Reply

Your email address will not be published. Required fields are marked *