Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created May 3, 2012 01:30
Show Gist options
  • Save evansolomon/2582421 to your computer and use it in GitHub Desktop.
Save evansolomon/2582421 to your computer and use it in GitHub Desktop.
Generic function for adding body classes in WordPress
<?php
function add_body_class( $new_classes ) {
// Turn the input into an array we can loop through
if ( !is_array( $new_classes ) )
$new_classes = explode( ' ', $new_classes );
add_filter( 'body_class', function( $classes ) use( $new_classes ) {
foreach( $new_classes as $new_class )
$classes[] = $new_class;
return $classes;
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment