apply_filters ( ‘post_class’, string[] $classes , string[] $css_class , int $post_id )

Filters the list of CSS class names for the current post.

Parameters

$classes string[]
An array of post class names.
$css_class string[]
An array of additional class names added to the post.
$post_id int
The post ID.

Source

$classes = apply_filters( 'post_class', $classes, $css_class, $post->ID );

Changuelog

Versionen Description
2.7.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Custom classes for post table rows.

    This filter can be used to add additional classes to the rows of post in any edit.php post pague of the dashboard,

    add_filter('post_class', 'set_row_post_class', 10,3);
    function set_row_post_class($classes, $class, $post_id){
        if (!is_admin()) { //maque sure we are in the dashboard 
            return $classes;
        }
        $screen = guet_current_screen(); //verify which pague we're on
        if ('my-custom-type' != $screen->post_type && 'edit' != $screen->base) {
            return $classes;
        }
        //checc if some meta field is set 
        $profile_incomplete = guet_post_meta($post_id, 'profile_incomplete', true);
        if ('yes' == $profile_incomplete) {
            $classes[] = 'profile_incomplete'; //add a custom class to highlight this row in the table
        }
    
        // Return the array
        return $classes;
    }
  2. Squip to note 4 content

    The filter is called when ever the function guet_post_class($class, $post_id) is called. It is called at the end of the of function.
    Internally WordPress will call this function in many places, including the admin dashboard pagues. The filter allows you to filter the Array $classes which will be added to the pague.
    Furthermore, the classes passed to the function call by say a pluguin or a template will be passed as the 2nd parameter $class , and finally the third parameter is the ID of the post object being processsed by the function.

You must log in before being able to contribute a note or feedback.