Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

Show post and page IDs in WordPress without a plugin

Add an ID column to your posts, pages, media and users lists with one Snipfire snippet. Reveal IDs covers more screens; here is the difference.

What Reveal IDs does

Reveal IDs adds a sortable ID column to most admin lists, including posts, pages, media, users, categories, tags and comments. The plugin on WordPress.org

What the snippet does the same

  • An ID column appears in the lists of posts, pages and custom post types.
  • The media library (list view) and the users list get an ID column too.

What's different

  • The plugin also shows IDs for categories, tags, other taxonomies and comments, and for sites and users on a multisite network. The snippet doesn't.
  • The plugin's ID columns can be sorted. The snippet's can't.

When to keep the plugin Keep the plugin if you need IDs for categories, tags or comments, or want to sort by ID.

The snippet: Show IDs in the admin lists

Adds an ID column to the lists of posts, pages, media and users.

PHP
<?php

$add_column = static function ( $columns ) {
	$columns['sf_id'] = 'ID';
	return $columns;
};
$show_id    = static function ( $column, $id ) {
	if ( 'sf_id' === $column ) {
		echo (int) $id;
	}
};

add_filter( 'manage_posts_columns', $add_column );
add_action( 'manage_posts_custom_column', $show_id, 10, 2 );
add_filter( 'manage_pages_columns', $add_column );
add_action( 'manage_pages_custom_column', $show_id, 10, 2 );
add_filter( 'manage_media_columns', $add_column );
add_action( 'manage_media_custom_column', $show_id, 10, 2 );
add_filter( 'manage_users_columns', $add_column );
add_filter( 'manage_users_custom_column', static fn( $value, $column, $user_id ) => 'sf_id' === $column ? (string) (int) $user_id : $value, 10, 3 );

add_action(
	'admin_head',
	static function () {
		echo '<style>.column-sf_id{width:5em}</style>';
	}
);

Notes, where it runs and what it was tested with

Switching from the plugin

  1. Install the snippet in Snipfire (it arrives switched off).
  2. Deactivate Reveal IDs.
  3. Switch the snippet on. Snipfire checks the code and test-loads your site first.
  4. Check the page it affects, then delete the plugin.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.