Created
January 9, 2014 17:19
-
-
Save germanny/8338063 to your computer and use it in GitHub Desktop.
body_class
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 | |
/** | |
* Add new classes to the $classes array | |
* http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters | |
*/ | |
add_filter('body_class','my_class_names'); | |
function my_class_names($classes) { | |
global $post; | |
if ( is_front_page() ) : | |
$classes[] = 'home'; | |
elseif ( is_page() ) : | |
$classes[] = $post->post_name; | |
elseif( is_archive() ) : | |
$classes[] = 'archive'; | |
elseif( is_404() ) : | |
$classes[] = 'error'; | |
elseif( is_search() ) : | |
$classes[] = 'search'; | |
endif; | |
// return the $classes array | |
return $classes; | |
} | |
?> |
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
<body <?php body_class(); ?>> |
Author
germanny
commented
Mar 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment