Title: post_class
Published: April 25, 2014
Last modified: February 24, 2026

---

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

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#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](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post-template.php#L607)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-template.php#L607-L607)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#related)󠁿

| Used by | Description | 
| [get_post_class()](https://developer.wordpress.org/reference/functions/get_post_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the post container element.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.7.0](https://developer.wordpress.org/reference/since/2.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#comment-content-1967)
 2.    [Aurovrata Venet](https://profiles.wordpress.org/aurovrata/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/post_class/#comment-1967)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%23comment-1967)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%23comment-1967)
 4.  Custom classes for post table rows.
 5.  This filter can be used to add additional classes to the rows of post in any `
     edit.php` post page of the dashboard,
 6.      ```php
         add_filter('post_class', 'set_row_post_class', 10,3);
         function set_row_post_class($classes, $class, $post_id){
             if (!is_admin()) { //make sure we are in the dashboard 
                 return $classes;
             }
             $screen = get_current_screen(); //verify which page we're on
             if ('my-custom-type' != $screen->post_type && 'edit' != $screen->base) {
                 return $classes;
             }
             //check if some meta field is set 
             $profile_incomplete = get_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;
         }
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%3Freplytocom%3D1967%23feedback-editor-1967)
 8.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/post_class/?output_format=md#comment-content-1966)
 9.    [Aurovrata Venet](https://profiles.wordpress.org/aurovrata/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/post_class/#comment-1966)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%23comment-1966)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%23comment-1966)
 11. The filter is called when ever the function `get_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 pages. The filter
     allows you to filter the Array `$classes` which will be added to the page. Furthermore,
     the classes passed to the function call by say a plugin or a template will be 
     passed as the 2nd parameter `$class`, and finally the third parameter is the ID
     of the post object being processed by the function.
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F%3Freplytocom%3D1966%23feedback-editor-1966)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_class%2F)
before being able to contribute a note or feedback.