Created
May 1, 2013 15:06
-
-
Save eddiemoya/5495823 to your computer and use it in GitHub Desktop.
Example body class filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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