When customized, WordPress administration interface becomes easier to manage and can significantly improve user experience. One popular customization is adding custom columns to post or user listing tables, which improves administrator data visibility. This guide will walk you through creating, populating, and sorting custom columns in the WordPress admin, complete with code examples, best practices, and troubleshooting tips.
Custom columns help you:

Use the manage_{$post_type}_posts_columns filter to insert a column to the post list. For example, let’s add a “Featured Image” column to the “Posts” screen:
add_filter('manage_posts_columns', 'add_custom_post_columns');
function add_custom_post_columns($columns) {
$columns['featured_image'] = 'Featured Image';
return $columns;
}
Replace posts with your post type slug (e.g., manage_product_posts_columns for a “product” CPT).
Use the manage_{$post_type}_posts_custom_column action to display content in the column:
add_action('manage_posts_custom _column', 'populate_custom_post_columns', 10, 2);
function populate_custom_post_columns($column, $post_id) {
if ($column === 'featured_image') {
$thumbnail = get_the_post_thumbnail($post_id, 'thumbnail');
echo $thumbnail ? $thumbnail : 'No Image';
}
}
This code checks if the current column is the “Featured Image” column and retrieves the post thumbnail. If no image exists, it displays “No Image.”
To insert a custom column to the user listing, use the manage_users_columns filter:
add_filter('manage_users_columns', 'add_custom_user_columns');
function add_custom_user_columns($columns) {
$columns['registration_date'] = 'Registration Date';
return $columns;
}
Use the manage_users_custom_column action to fill in the data for the new column:
add_action('manage_users_custom_column', 'populate_custom_user_columns', 10, 3);
function populate_custom_user_columns($output, $column_name, $user_id) {
if ($column_name === 'registration_date') {
$user_info = get_userdata($user_id);
echo date('Y-m-d', strtotime($user_info->user_registered));
}
}
This code retrieves the registration date of the user and formats it for display.
To make the custom column sortable, use the manage_edit-{$post_type}_sortable_columns filter:
add_filter('manage_edit-posts_sortable_columns', 'register_sortable_columns');
function register_sortable_columns($columns) {
$columns['featured_image'] = 'featured_image';
return $columns;
}
Use the pre_get_posts action to modify the query when sorting by the custom column:
add_action('pre_get_posts', 'sort_custom_columns');
function sort_custom_columns($query) {
if (!is_admin() || !$query->is_main_query()) return;
if ('featured_image' === $query->get('orderby')) {
$query->set('meta_key', '_thumbnail_id');
$query->set('orderby', 'meta_value');
}
}
This code checks if the query is for the admin area and modifies it to sort by the featured image meta key.
For user columns, use the following code:
add_filter('manage_edit-users_sortable_columns', 'register_sortable_user_columns');
function register_sortable_user_columns($columns) {
$columns['registration_date'] = 'registration_date';
return $columns;
}
Modify the user query similarly:
add_action('pre_get_users', 'sort_custom_user_columns');
function sort_custom_user_columns($query) {
if (!is_admin() || !$query->is_main_query()) return;
if ('registration_date' === $query->get('orderby')) {
$query->set('orderby', 'user_registered');
}
}
This code allows sorting users by their registration date.
For performance, ensure that any custom fields used for sorting are indexed. This process can significantly speed up queries, especially with large datasets.
To reduce database load, consider caching the data displayed in custom columns. You can also temporarily store results using transients or object caching.
For a more dynamic experience, implement AJAX to load column data without refreshing the page. This implementation can enhance user experience, especially for large datasets.
If your custom columns do not show up, check the hook priority and ensure your function is correctly registered.
If sorting does not function as expected, verify that the query is correctly modified and that the data is indexed.
Avoid heavy queries in custom columns. If you experience low performance, consider optimizing your database or using caching strategies.
Adding custom columns to the WordPress admin tables can greatly enhance the management of posts and users. By following the steps outlined in this guide, you can create, populate, and sort custom columns effectively. Remember to consider performance and security best practices while implementing these features. With these enhancements, you can tailor the WordPress admin experience to better suit your needs and improve overall efficiency.

Hassan Tahir wrote this article, drawing on his experience to clarify WordPress concepts and enhance developer understanding. Through his work, he aims to help both beginners and professionals refine their skills and tackle WordPress projects with greater confidence.