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!


Sr. Software Engineer

Posted in Wordpress
12 comments on “How Add custom parameters into the body_class() function ?
  1. I really like what you guys are usually up too. This type of clever work
    and coverage! Keep up the superb works guys
    I’ve added you guys to our blogroll.

  2. This paragraph will assist the internet people for
    building up new weblog or even a blog from start to

  3. 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.

  4. Justin says:

    I like to disseminate understanding that I have built up through the yr to help improve team

  5. 外燴 says:

    I like to share knowledge that will I’ve accumulated through the yr to assist improve group efficiency.

  6. Tremendous things here. I’m very happy to see your article.
    Thank you a lot and I’m looking forward to touch you.

    Will you please drop me a e-mail?

  7. This is a topic which is close to my heart… Thank you! Exactly
    where are your contact details though?

  8. Erica says:

    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

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Recent Posts
%d bloggers like this: