php – Adding a tag_ID column into Categories inside the admin dashboard?

Question

So right now there are four columns when you navigate to Posts > Categories (or your custom Taxonomy):

Name | Description | Slug | Count

I’m working with taxonomy term_id a lot, so I need to see the id column as well.

Is there a way to add a Sortable ID column?

I was looking, but couldn’t find it.

If anyone have made this for themselves, I would really appreciate if someone could share the functions.php code.

Thanks.

in progress 0
robert0 3 weeks 2021-09-04T06:52:11-05:00 0 Answer 0 views 0

Answer ( 1 )

    0
    2021-09-05T15:18:11-05:00

    You can do it like so:

    1. Use the manage_<screen ID>_columns filter to add the “ID” column.

      Example for the default category taxonomy where <screen ID> is edit-category — for other taxonomies, it would be edit-<taxonomy> like edit-post_tag:

      add_filter( 'manage_edit-category_columns', 'my_manage_edit_category_columns' );
      function my_manage_edit_category_columns( $columns ) {
          // Add the "ID" column.
          $columns['term_id'] = 'ID';
          // .. add other columns, if you want to.
      
          return $columns;
      }
      
    2. Use the manage_<screen ID>_sortable_columns filter to make the “ID” column be sortable.

      Example for the default category taxonomy (the screen ID format is the same as above):

      add_filter( 'manage_edit-category_sortable_columns', 'my_manage_edit_category_sortable_columns' );
      function my_manage_edit_category_sortable_columns( $sortable_columns ) {
          // Add the "ID" column.
          $sortable_columns['term_id'] = 'term_id';
          // .. add other columns, if you want to.
      
          return $sortable_columns;
      }
      
    3. Use the manage_<taxonomy>_custom_column filter to display the actual term ID in the “ID” column.

      Example for the default category taxonomy:

      add_filter( 'manage_category_custom_column', 'my_manage_category_custom_column', 10, 3 );
      function my_manage_category_custom_column( $content, $column_name, $term_id ) {
          switch ( $column_name ) {
              case 'term_id':
                  $content = $term_id;
                  break;
          }
      
          return $content;
      }
      

Leave an answer

Browse
Browse