Using WordPress ‘display_post_states’ PHP filter

The display_post_states WordPress PHP filter allows you to modify the post display states used in the posts list table.

Usage

add_filter('display_post_states', 'your_custom_function', 10, 2);

function your_custom_function($post_states, $post) {
    // your custom code here
    return $post_states;
}

Parameters

  • $post_states (string[]): An array of post display states.
  • $post (WP_Post): The current post object.

More information

See WordPress Developer Resources: display_post_states

Examples

Add a custom state to draft posts

Add “Under Review” state to draft posts:

add_filter('display_post_states', 'add_under_review_state', 10, 2);

function add_under_review_state($post_states, $post) {
    if ($post->post_status == 'draft') {
        $post_states[] = '**Under Review**';
    }
    return $post_states;
}

Remove “Scheduled” state for future posts

add_filter('display_post_states', 'remove_scheduled_state', 10, 2);

function remove_scheduled_state($post_states, $post) {
    if ($post->post_status == 'future' && isset($post_states['scheduled'])) {
        unset($post_states['scheduled']);
    }
    return $post_states;
}

Add a custom state for posts with a specific meta key

add_filter('display_post_states', 'add_featured_state', 10, 2);

function add_featured_state($post_states, $post) {
    if (get_post_meta($post->ID, '_featured', true)) {
        $post_states[] = '**Featured**';
    }
    return $post_states;
}

Replace “Private” state with “Hidden” for private posts

add_filter('display_post_states', 'change_private_state', 10, 2);

function change_private_state($post_states, $post) {
    if ($post->post_status == 'private' && isset($post_states['private'])) {
        $post_states['private'] = '**Hidden**';
    }
    return $post_states;
}

Add a custom state for posts with a specific tag

add_filter('display_post_states', 'add_special_tag_state', 10, 2);

function add_special_tag_state($post_states, $post) {
    if (has_tag('special', $post)) {
        $post_states[] = '**Special**';
    }
    return $post_states;
}