How to Display Custom Taxonomy Columns in the WordPress Admin
Managing content and organizing your website's information can become a challenge as your WordPress site grows. One powerful way to keep things tidy and easily accessible is to utilize custom taxonomies.
Custom taxonomies allow you to create your own classification systems beyond the default categories and tags. This gives you the flexibility to group and sort your content in ways that are most relevant to your specific website and audience.
However, one common frustration that WordPress developers often encounter is how to actually display those custom taxonomy terms in the admin area. By default, custom taxonomy columns are not shown, leaving you to search through each individual post to see what terms have been assigned.
Fortunately, there's a simple parameter you can add when registering your custom taxonomy that will make those columns instantly appear. In this guide, we'll walk through the step-by-step process of adding custom taxonomy columns to your WordPress admin.
What is the show_admin_column
Parameter?
The show_admin_column
parameter is a boolean (true/false) option that you can include when registering a new custom taxonomy in WordPress. When set to true
, it will automatically create a new column in the admin area for that taxonomy, making it easy for users to view and manage the terms associated with each post.
Here's an example of how you would register a new "Book Category" taxonomy with the show_admin_column
parameter:
function books_init() {
$labels = array(
'name' => _x( 'Book Categories', 'taxonomy general name', 'textdomain' ),
'singular_name' => _x( 'Book Category', 'taxonomy singular name', 'textdomain' ),
'search_items' => __( 'Search Book Categories', 'textdomain' ),
'all_items' => __( 'All Book Categories', 'textdomain' ),
'parent_item' => __( 'Parent Book Category', 'textdomain' ),
'parent_item_colon' => __( 'Parent Book Category:', 'textdomain' ),
'edit_item' => __( 'Edit Book Category', 'textdomain' ),
'update_item' => __( 'Update Book Category', 'textdomain' ),
'add_new_item' => __( 'Add New Book Category', 'textdomain' ),
'new_item_name' => __( 'New Book Category Name', 'textdomain' ),
'menu_name' => __( 'Book Categories', 'textdomain' ),
);
register_taxonomy(
'book_cat',
'book',
array(
'labels' => $labels,
'rewrite' => array( 'slug' => 'bcat' ),
'show_admin_column' => true,
)
);
}
add_action( 'init', 'books_init' );
In this example, we're registering a new "Book Category" taxonomy that will be associated with the "book" post type. By including 'show_admin_column' => true,
in the taxonomy arguments, we're telling WordPress to automatically create a new column in the "Books" admin list table to display the assigned Book Category terms.
Now, whenever a new "Book" post is added or edited, the assigned Book Category will be visible in the admin area without any additional code required.
Benefits of Using show_admin_column
Displaying your custom taxonomy columns in the WordPress admin area provides several key benefits:
-
Improved Content Organization: Being able to quickly see which taxonomy terms are assigned to each piece of content makes it much easier to manage and organize your website's information. This is especially valuable as your site grows and you have more content to keep track of.
-
Faster Content Management: Instead of having to open each individual post to check the assigned taxonomy terms, you can now see everything at a glance in the admin list table. This streamlines the content management workflow and saves you time.
-
Better User Experience: For multi-author sites or sites with multiple content editors, displaying the custom taxonomy columns creates a more intuitive and efficient admin experience. This can lead to better adoption of your custom taxonomies and more consistent tagging/categorization of content.
-
Enhanced Data Visibility: The ability to sort and filter posts by their assigned taxonomy terms opens up new ways to analyze your content and gain valuable insights. This can be especially useful for sites with e-commerce, directory, or other structured content elements.
Overall, taking the small step to enable the show_admin_column
parameter is a simple yet impactful way to improve the manageability and usability of your WordPress site's custom taxonomies.
How to Customize the Custom Taxonomy Columns
While the default show_admin_column
functionality is great, you may want to further customize the appearance and behavior of your custom taxonomy columns. Fortunately, WordPress provides several helpful hooks and filters that allow you to do just that.
1. Change the Column Title
By default, the column title will match the "singular name" label you defined when registering the taxonomy. If you want to use a different title, you can use the manage_{$taxonomy}_custom_column
hook to modify the column header:
add_filter( 'manage_book_cat_custom_column', 'change_book_cat_column_title', 10, 3 );
function change_book_cat_column_title( $column_title, $taxonomy, $column_name ) {
if ( 'book_cat' === $taxonomy && 'book_cat' === $column_name ) {
$column_title = 'Book Category';
}
return $column_title;
}
In this example, we're changing the "Book Category" column title to simply "Book Category".
2. Customize the Column Content
The default column content will simply display the assigned taxonomy terms. However, you may want to display additional information or formatting. You can use the manage_{$taxonomy}_custom_column
hook again to customize the column output:
add_action( 'manage_book_cat_custom_column', 'display_book_cat_column_content', 10, 3 );
function display_book_cat_column_content( $content, $column_name, $post_id ) {
if ( 'book_cat' === $column_name ) {
$terms = get_the_terms( $post_id, 'book_cat' );
if ( $terms && ! is_wp_error( $terms ) ) {
$term_links = array();
foreach ( $terms as $term ) {
$term_links[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array(
'post_type' => get_post_type( $post_id ),
'book_cat' => $term->slug,
), 'edit.php' ) ),
esc_html( $term->name )
);
}
$content = join( ', ', $term_links );
} else {
$content = '—';
}
}
return $content;
}
In this example, we're modifying the column content to display the assigned Book Category terms as clickable links that filter the post list to show only posts with that category. If no categories are assigned, we display a dash (—
) instead.
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.
3. Enable Sorting by the Custom Taxonomy Column
By default, the custom taxonomy columns are not sortable in the admin list table. If you want to allow users to sort the posts by the assigned taxonomy terms, you can use the manage_edit-{$post_type}_sortable_columns
filter:
add_filter( 'manage_edit-book_sortable_columns', 'make_book_cat_column_sortable' );
function make_book_cat_column_sortable( $sortable_columns ) {
$sortable_columns['book_cat'] = 'book_cat';
return $sortable_columns;
}
This code adds the "Book Category" column to the list of sortable columns for the "book" post type. Now, users can click the column header to sort the posts by their assigned Book Category terms.
Keep in mind that making a custom taxonomy column sortable requires some additional database queries and logic to ensure the sorting works properly. You may need to add custom SQL clauses to your post queries to handle the sorting functionality.
Conclusion
Displaying custom taxonomy columns in the WordPress admin is a simple yet powerful way to improve your site's content organization and management. By taking advantage of the show_admin_column
parameter when registering your taxonomies, you can instantly create dedicated columns that make it easier for users to view and interact with your site's structured data.
Furthermore, the various hooks and filters available allow you to further customize the appearance and behavior of these custom columns to suit your specific needs. Whether you want to change the column title, modify the content, or enable sorting, WordPress provides the flexibility to make your admin interface work for you.
If you're looking to take your WordPress site's taxonomy management to the next level, be sure to leverage the show_admin_column
functionality. It's a small change that can have a big impact on the overall usability and efficiency of your admin area.
Flowpoint.ai can help you identify all the technical errors that are impacting conversion rates on your WordPress website and directly generate recommendations to fix them, including improvements to your custom taxonomy setup