I’m trying to add a column to the trash page for posts and pages but can’t find a way to hook into that specific area. I’ve been able to use functions like manage_posts_columns and manage_pages_columns to add columns, but these hooks add columns to more than just the trash view.

I can see from the URL that the trash has post_status=trash but haven’t found a way to hook into that. The generic manage_{$post_type}_posts_columns doesn’t seem to fit since I need a post_status, not a post_type.

I’ve also looked at get_current_screen but it doesn’t return a post_status. Am I missing a function or obvious way to do this?

1 Answer
1

You can check the value of the post_status query variable and make sure that it’s set to trash:

function wpse239286_trash_column( $columns ) {

    // Bail if we're not looking at trash.
    $status = get_query_var( 'post_status' );
    if ( 'trash' !== $status ) {
        return $columns;
    }

    return array_merge( $columns, 
        array( 'trash_column' => __( 'Trash Column', 'text-domain' ) )
    );
}
add_filter( 'manage_posts_columns' , 'wpse239286_trash_column' );
add_filter( 'manage_pages_columns' , 'wpse239286_trash_column' );

Leave a Reply

Your email address will not be published. Required fields are marked *