Skip to content

Instantly share code, notes, and snippets.

@eddiemoya
Created May 1, 2013 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddiemoya/5495823 to your computer and use it in GitHub Desktop.
Save eddiemoya/5495823 to your computer and use it in GitHub Desktop.
Example body class filter
<?php
/**
* Do not call this function directly, add it to the body_class filter
*
* Conditionally adds classes to the body class of a page for styling purposes.
* These examples are from the Kmart Fashion and BirthdayClub themes.
*
* @author Eddie Moya
*
* @param type $classes
* @return array
*/
function filter_body_class($classes) {
if (is_category())
$classes[] = get_queried_object()->category_nicename;
if(isset($_GET['s'])){
$classes[] = 'search-results';
}
if(is_single()){
if('section' == get_post_type()){
$classes = array_diff($classes, array('single', 'single-section'));
}
}
//print_pre($obj);
return $classes;
}
add_filter('body_class', 'filter_body_class');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment