WordPress: How to change the Edit Category / Taxonomy admin panel

December 1st, 2010


About the Author: Dan

I’m Dan Smart, a 38 year old website developer, based in Swansea, UK. I have worked in the software development industry for over 15 years, with experience in web development, mobile handset development, and mobile networks. I work both on websites and web applications with systems such as Wordpress, Laravel, Backbone, Angular.js, node.js and mobile app development with PhoneGap, iOS, and Android. When I’m not developing websites and software, I am a keen runner, involved with mime performance group Innovo Physical Theatre, and also actively involved in my local church.

* Follow me on Twitter or contact me


I hunted high and low over the web to try and find a tutorial on how to modify the headings (and data) shown in the Edit Category (or Edit Taxonomy if you’re using a custom taxonomy) admin panel. This is useful if you’re using custom meta data in a category, or if you want to hide certain fields (e.g. the description).

Who is this post for?

This post expects a good knowledge of WordPress and PHP, and an understanding of filters and actions.

This was written for WordPress version 3.0.x.

The Edit Categories panel

The Edit Categories panel (below) has standard categories of ‘Name’, ‘Description’, ‘Slug’, and ‘Posts’.

Hiding the Description Field

What if you wanted to hide the ‘Description’ column for Post Category?

The hook that you’re looking for is ‘manage_edit-category_columns’. This receives the column headings, which we can modify prior to their output, as follows:

  1. function manage_my_category_columns($columns)
  2. {
  3.  // only edit the columns on the current taxonomy
  4.  if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'category' )
  5.  return $columns;
  6.  
  7.  // unset the description columns
  8.  if ( $posts = $columns['description'] ){ unset($columns['description']); }
  9.  
  10.  return $columns;
  11. }
  12. add_filter('manage_edit-category_columns','manage_my_category_columns');

So what we did above was to first check if this is the correct taxonomy (classification of items – in our case, ‘category’).

Once we know we’re editing the correct columns, we have an array $columns of the column names, and we just unset this array item. It will no longer appear in the column list – neither header rows nor data row.

This is called by the filter ‘manage_edit-category_columns’.

Our result is as below:

That looks a lot tidier. We can also do the same to remove the slug column by unsetting the ‘slug’ array item.

Note for Custom Taxonomies

The name of the hook is dependent on the taxonomy, so for a ‘people’ taxonomy ‘manage_edit-category_columns’ becomes ‘manage_edit-people_columns’.

Adding a Column

So that was removing a column, but what about adding a column of data.

This would be relevant if you have meta data stored with each category (maybe using the Category Meta plugin, or a method somewhat like on this post), or perhaps you wish to display another piece of data to the user.

In this case, you add an array item to the columns list in the ‘manage_edit-categories_columns’ hook containing your column name, and also hook onto the ‘manage_category_custom_column’ hook.

Step 1: Adding the column name

  1. function manage_my_category_columns($columns)
  2. {
  3.  if ( !isset($_GET['taxonomy']) || $_GET['taxonomy'] != 'category' )
  4.  return $columns;
  5.  
  6.  if ( $posts = $columns['slug'] ){ unset($columns['slug']); }
  7.  if ( $posts = $columns['description'] ){ unset($columns['description']); }
  8.  
  9.  // add 'My Column'
  10.  $columns['my_column'] = 'My Column';
  11.  
  12.  return $columns;
  13. }
  14. add_filter('manage_edit-category_columns','manage_my_category_columns');

So we have added a column with an index of ‘my_column’, and a visual title of ‘My Column’.

Next we want to put the data in it:

  1. function manage_category_custom_fields($deprecated,$column_name,$term_id)
  2. {
  3.  if ($column_name == 'my_column') {
  4.    echo 'test';
  5.  }
  6. }
  7. add_action('manage_category_custom_column','manage_category_custom_fields',10,3);

So we hook onto the ‘manage_category_custom_column’ action, which passes in our column name and the term id, and in this instance we are displaying ‘test’:

And as you can see, we have our test data showing.

In terms of showing specific data per category term, use the $term_id as your specific identifier to get any meta data associated with this category.

And that’s it!

I hope this was useful – if so, please let me know on the comments. Any queries please let me know.


Switch to mobile version