Display Post and Page IDs in WordPress Admin Panel

The provided code adds a new “ID” column to the post and page lists in the WordPress admin dashboard, displaying the unique post or page ID for each item. Thus this WordPress customization is making it easier for administrators to quickly reference or identify the post/page by its ID.

// Add a unified ID column to the post and page lists
function ts_custom_add_id_column($columns) {
    $columns['id'] = 'ID'; // Add an 'ID' column
    return $columns;
}
add_filter('manage_posts_columns', 'ts_custom_add_id_column'); // For posts
add_filter('manage_pages_columns', 'ts_custom_add_id_column'); // For pages

// Populate the ID column with the post/page ID
function ts_custom_id_column_content($column_name, $post_id) {
    if ($column_name == 'id') {
        echo $post_id; // Display the ID
    }
}
add_action('manage_posts_custom_column', 'ts_custom_id_column_content', 10, 2); // For posts
add_action('manage_pages_custom_column', 'ts_custom_id_column_content', 10, 2); // For pages