NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Last modified : Nov 17 2021
Estimated reading time : 1 minute, 20 seconds - 105 words
Share the post "How to Add Pages/Posts IDs In WordPress Admin Columns"
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; } }