Add IDs to Posts/Pages columns in WordPress admin

Spotting your posts or pages IDs involves various clicks especially if permalinks are enabled in your Wordpress Website. In case you have none IDs permalinks enabled you will need to navigate to your posts list and click edit a given post so that you can copy its id from the URL.

The following PHP code snippet makes it a breeze. Once you paste the code in your functions.php file a new column will appear with the name ‘ID’ on your pages, posts, and custom post types lists. Now, you get access to all your posts IDs in one single place.

PHP
add_filter('manage_posts_columns', 'wph_posts_columns_ids', 5);
add_action('manage_posts_custom_column', 'wph_posts_new_id_columns', 5, 2);
add_filter('manage_pages_columns', 'wph_posts_columns_ids', 5);
add_action('manage_pages_custom_column', 'wph_posts_new_id_columns', 5, 2);

function wph_posts_columns_ids($defaults){
    $defaults['wps_post_id'] = __('ID');
    return $defaults;
}

function wph_posts_new_id_columns($column_name, $id){
    if($column_name === 'wps_post_id'){
        echo $id;
    }
}