Tag Archives: class

If you wanted to add emphasis to the first post in your blog adding this snippet to the functions.php of your WordPress theme will add the class of “first” to your first post.

Add this code to your functions.php file.

add_filter( 'post_class', 'wps_first_post_class' );
function wps_first_post_class( $classes ) {
    global $wp_query;
    if( 0 == $wp_query->current_post )
        $classes[] = 'first';
        return $classes;

This WordPress snippet is very handy if you wish to add the category ID to the body or post-class for ie. targeting CSS styles and such.

Add this to your functions.php file.

function category_id_class($classes) {
     global $post;
          foreach((get_the_category($post->ID)) as $category)
               $classes [] = 'cat-' . $category->cat_ID . '-id';
     return $classes;
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');