Created
April 30, 2012 10:47
-
-
Save bmcminn/2557319 to your computer and use it in GitHub Desktop.
PHP: post_class() filter - add custom post classes
This file contains hidden or 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 | |
// Practically verbatim from the WordPress codex | |
// http://codex.wordpress.org/Function_Reference/post_class#Add_Classes_By_Filters | |
add_filter('post_class','MYTHEME_post_class_cats'); | |
function MYTHEME_post_class_cats($classes) { | |
global $post; | |
foreach((get_the_category($post->ID)) as $category) { | |
$classes[] = $category->category_nicename; | |
$classes[] = $category->ID; | |
return $classes; | |
} | |
} // MYTHEME_post_class_cats($classes) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment