Is there any way to add a custom css class based on post data in the custom post type admin table?

wordpress custom class in admin table row

1 Answer 1


Finally got a solution. Founded in WordPress Documentation

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;
  • I think it should be if ('my-custom-type' != $screen->post_type || 'edit' != $screen->base) { (|| instead of &&) Commented Jan 20, 2023 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.