How to set default visible columns in posts list, for all users

Since the question was about columns and not meta boxes and I needed this solution, Ioannis’ reply got me on the right track.

The filter hook in question is default_hidden_columns.

This is the solution I ended up with to set my ad_shortcode column to be hidden by default. You should know that this is just the default. As soon as the page was visited, the default is no longer be used. Look for a meta key that includes columnshidden in wp_usermeta and remove it when testing.

add_filter( 'default_hidden_columns', 'hide_ad_list_columns', 10, 2 );
function hide_ad_list_columns( $hidden, $screen ) {
    // "edit-advanced_ads" needs to be adjusted to your own screen ID, this one is for my "advanced_ads" post type
    if( isset( $screen->id ) && 'edit-advanced_ads' === $screen->id ){      
        $hidden[] = 'ad_shortcode';     
    }   
    return $hidden;
}

Leave a Comment