Quantcast
Channel: Crunchify
Viewing all articles
Browse latest Browse all 1037

How to Move WordPress Admin Column Before OR After any other Column? manage_post_columns Hook

$
0
0

Crunchify WordPress Tips How to Move WordPress Admin Column Before OR After any other Column? manage post columns Hook

WordPress is pretty amazing. More than 33k plugins in WordPress plugin repository. There are lots of customization we could do with the hooks and APIs available for us to use. Have you ever wonder – how to move admin columns?

In this WordPress Tutorial we will go over steps on how to switch/modify WordPress Admin Console Post columns.

Let’s take a look at this default WordPress Post Column.

WordPress Admin Post Column Before How to Move WordPress Admin Column Before OR After any other Column? manage post columns Hook

Let’s move Categories column before Title column.

WordPress Admin Post Column After How to Move WordPress Admin Column Before OR After any other Column? manage post columns Hook

Let’s take a look at below code snippet which you need to include into your WordPress Theme’s functions.php file.  manage_posts_columns is a filter applied to the columns shown on the manage posts screen. It’s applied to posts of all types except pages.

// Move "Categories" column before "title" column
function crunchify_reorder_columns($columns) {
  $crunchify_columns = array();
  $categories = 'categories'; 
  $title = 'title'; 
  foreach($columns as $key => $value) {
    if ($key==$title){
      $crunchify_columns[$categories] = $categories;
    }
      $crunchify_columns[$key] = $value;
  }
  return $crunchify_columns;
}
add_filter('manage_posts_columns', 'crunchify_reorder_columns');

Now let’s take a look at scenario in which you may need to move couple of more columns before title columns, i.e. Move tags, categories, author column before title column. Take a look at below image.

WordPress Admin Post Column move categories date tags before title column How to Move WordPress Admin Column Before OR After any other Column? manage post columns Hook

Please use below code to achieve the same.

function crunchify_reorder_columns($columns) {
  $crunchify_columns = array();
  $title = 'title'; 
  foreach($columns as $key => $value) {
    if ($key==$title){
      $crunchify_columns['date'] = '';   // Move date column before title column
      $crunchify_columns['author'] = '';   // Move author column before title column
      $crunchify_columns['tags'] = '';   // Move tags column before title column
    }
      $crunchify_columns[$key] = $value;
  }
  return $crunchify_columns;
}
add_filter('manage_posts_columns', 'crunchify_reorder_columns');

Browse list of similar more than 200 WordPress Articles.

Have anything to add to this article? Please chime in and join the conversion.


The post How to Move WordPress Admin Column Before OR After any other Column? manage_post_columns Hook appeared first on Crunchify.
Author: Arpit Shah


Viewing all articles
Browse latest Browse all 1037

Trending Articles