Skip to Content
Menu

post_classes()

Adds useful information to post tags as classes.

PHP March 16, 2017

Usage

This function runs automatically, so it is not called manually. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Functions.php on line 3012.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function post_classes($classes){
                if ( !$this->is_admin_page() ){
                    $this->timer('Nebula Post Classes');
    
                    global $post;
                    global $wp_query;
    
                    if ( $wp_query->current_post === 0 ){ //If first post in a query
                        $classes[] = 'first-post';
                    }
                    if ( is_sticky() ){
                        $classes[] = 'sticky';
                    }
                    $classes[] = 'nebula-entry';
    
                    if ( !is_page() ){
                        $classes[] = 'date-day-' . strtolower(get_the_date('l'));
                        $classes[] = 'date-ymd-' . strtolower(get_the_date('Y-m-d'));
                        $classes[] = 'date-month-' . strtolower(get_the_date('F'));
                    }
    
                    if ( !empty($post) ){
                        foreach ( get_the_category($post->ID) as $category ){
                            $classes[] = 'cat-id-' . $category->cat_ID;
                        }
                    }
    
                    $classes[] = 'author-id-' . $post->post_author;
                    if ( is_multi_author() ){
                        $classes[] = 'multi-author';
                    }
    
                    //If this post has a featured image
                    if ( has_post_thumbnail() ){
                        $classes[] = 'has-featured-image';
                    }
    
                    //Remove "hentry" meta class on pages or if Author Bios are disabled
                    if ( is_page() || !$this->get_option('author_bios') ){
                        $classes = array_diff($classes, array('hentry'));
                    }
    
                    $this->timer('Nebula Post Classes', 'end');
                }
    
                return $classes;
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?