function my_list_table_primary_column( $default, $screen ) {// Alter the primary column in edit.php table(s)
// if we want the 'Name' column to be the primary column, on Users screen
if ( 'users' === $screen ) {
$default = 'name';
}
// if we want to set the primary column for CPT
if ( 'edit-my_custom_post_type' === $screen ) {
$default = 'my_custom_column_name';
}
return $default;
}
add_filter( 'list_table_primary_column', 'my_list_table_primary_column', 10, 2 );
If you’re adding a column in the first position, it’s important to set this column as primary because WordPress has CSS rules that are applied for columns after the primary column. Otherwise, the list table can render with some layout issues.
A simple example for Users table and CPT table
For further management of columns, check:
https://developer.wordpress.org/reference/hooks/manage_post_type_posts_columns/
To add/remove/rename columns
https://developer.wordpress.org/reference/hooks/manage_post-post_type_posts_custom_column/
To set the custom column values
If you’re adding a column in the first position, it’s important to set this column as primary because WordPress has CSS rules that are applied for columns after the primary column. Otherwise, the list table can render with some layout issues.
Example of CSS rule used by WordPress:
.wp-list-table tr:not(.inline-edit-row):not(.no-items) td.column-primary~td:not(.check-column)