Rearranging the Post Admin Columns

The basic WordPress Post admin column is fairly well known to all. Luckily these columns can be arranged pretty much anyway you want. In one of my earlier post I explained how to add custom column which is bit different from rearranging them. This particular snippet could be really useful if you want to display custom column and organize them based on your own requirement.

Also, please remember that you can use this snippet to add custom column and to display post metadata. So, lets get started.

<?php // rearrange the columns
function rearrange_posts_admin_columns($columns) {
   $columns = array (
      'cb' => '<input type="checkbox">',
      'title' => 'Title',
      'date' => 'Date',
      'author' => 'Author',
      'category' => 'Category',
      'tags' => 'Tags',
      'id' => 'ID');
   return $columns; }
add_filter('manage_posts_columns','rearrange_posts_admin_columns');
// display relevant data
function posts_column_values($column_value,$post_id) {
   switch ($column_value) {
      case 'id' : echo $post_id; break;
      case 'category' : echo get_the_category_list(',',$post_id); break;
   default: } }
add_action('manage_posts_custom_column','posts_column_values',10,2);
?>

This snippet produces the following result. Let’s take a look at a screenshot.

Rearranged Posts ColumnsRearranged Posts Columns from WordPress Admin Panel.

As you can see from this screenshot, I added a new column to display the post “ID” at the end and also brought the “Date” column right after the “Title” column. Let’s not forget that the “Date” column generally suppose to be at the end.

Explanation

On the first portion of the snippet, I created a function to rearrange the columns. This is where you can add or remove certain column. We are doing that using the $columns variable which holds the array parameters and values. On the second portion of the snippet I am simply using switch statement to grab the values and display them. Remember that some of the columns values don’t require our help as they are being supported by the native WP functions. Then again if you want you can modify them as you wish but that’s more in depth topic to talk about.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from HTMLify, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.