Skip to content

Instantly share code, notes, and snippets.

@marcboivin
Created July 29, 2011 14:12
Show Gist options
  • Save marcboivin/1113876 to your computer and use it in GitHub Desktop.
Save marcboivin/1113876 to your computer and use it in GitHub Desktop.
Add a class to your body, the simple way
<?php
/*
WordPress now has a hook to add a body class. But it's kind of annoying
to deal with the add action and everything, so I made a little tiny wrapper
function that works only in php 5.3 + but still, makes my life easier when making
themes.
*/
function add_class_body($class){
add_filter('body_class', function($classes) use ($class){
$classes[] = $class;
return $classes;
}, 100 ,1);
}
/*
Now you can just call add_body_class('myclass');
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment