NB: Make sure you do a back up of your theme, files and database before attempting the tutorials

How to Add Pages/Posts ID In Wordpress Admin Columns
Easy
Web Hosting Canada

Last modified : Nov 17 2021

Estimated reading time : 1 minute, 20 seconds - 105 words

With this tutorial, we will show you how to use two filters that will allow us to display the pages and posts ID in properly identified columns in the WordPress users section of your website. The first filter will build the properly identified column manage_pages_columns and manage_posts_columns.

Once that’s done, we want to display the IDs in our columns. Two more filters are required: manage_posts_custom_column and manage_pages_custom_column.

These filters can also be used for custom post types sometimes used to generate portfolios, testimonials, products, etc…

add_filter( 'manage_pages_columns', 'pages_add_id_column', 5 );
add_action( 'manage_pages_custom_column', 'pages_id_column_content', 5, 2 );
function pages_add_id_column( $columns ) {
   $columns['monid'] = 'ID';
   return $columns;
}

function pages_id_column_content( $column, $id ) {
  if( 'monid' == $column ) {
    echo $id;
  }
}


add_filter( 'manage_posts_columns', 'posts_add_id_column', 5 );
add_action( 'manage_posts_custom_column', 'posts_id_column_content', 5, 2 );
function posts_add_id_column( $columns ) {
   $columns['monid'] = 'ID';
   return $columns;
}

function posts_id_column_content( $column, $id ) {
  if( 'monid' == $column ) {
    echo $id;
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>