Admin & Dashboard PHP Beginner

Show Post IDs in Admin Lists

Add an ID column to the posts and pages lists, so you can find IDs for shortcodes and settings without hovering over links.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 17 lines
function nahnu_id_column( array $columns ): array {
	return array_slice( $columns, 0, 1, true ) + [ 'nahnu_id' => 'ID' ] + array_slice( $columns, 1, null, true );
}
function nahnu_id_column_value( string $column, int $post_id ): void {
	if ( 'nahnu_id' === $column ) {
		echo (int) $post_id;
	}
}

add_filter( 'manage_posts_columns', 'nahnu_id_column' );
add_filter( 'manage_pages_columns', 'nahnu_id_column' );
add_action( 'manage_posts_custom_column', 'nahnu_id_column_value', 10, 2 );
add_action( 'manage_pages_custom_column', 'nahnu_id_column_value', 10, 2 );

add_action( 'admin_head', function (): void {
	echo '<style>.column-nahnu_id{width:60px}</style>';
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Shortcodes, page builder settings and plugin options often ask for a post or page ID. WordPress only shows it in the edit link’s URL. This snippet adds an ID column to every post type list.

How it works

manage_posts_columns (all post types except pages) and manage_pages_columns add the column right after the checkbox. The matching _custom_column actions print the ID, and a line of CSS keeps the column narrow.

Things to watch

  • The column can be hidden per user from Screen Options at the top of the list.
  • Custom post types use the same hooks, so the column appears for products and other types too.

How to test it

Open Posts → All Posts. An ID column should appear next to the titles.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only