Home / Admin / Display Post and Page IDs in WordPress Columns
Duplicate Snippet

Embed Snippet on Your Site

Display Post and Page IDs in WordPress Columns

This PHP code enables you to display the IDs of posts and pages within WordPress columns. By incorporating this code into your WordPress theme or plugin, you can conveniently view the unique identifiers of your posts and pages in the admin panel's listing view. This can be particularly useful for developers and administrators who need a quick reference to these IDs for various tasks, such as customization or troubleshooting. The code enhances the management of your content by adding an extra layer of information to the admin interface.

// If you are seeing the “IDs” twice, remove the following line

$columns['post_id'] = 'ID';

Code Preview
php
<?php
// // Add custom columns to post and page lists
function custom_add_id_columns($columns) {
    $columns['post_id'] = 'ID'; // For Posts
    $columns['page_id'] = 'ID'; // For Pages
    return $columns;
}
add_filter('manage_posts_columns', 'custom_add_id_columns');
add_filter('manage_pages_columns', 'custom_add_id_columns');
// Populate the custom columns with IDs
function custom_id_column_content($column_name, $post_id) {
    if ($column_name == 'post_id' || $column_name == 'page_id') {
        echo $post_id;
    }
}
add_action('manage_posts_custom_column', 'custom_id_column_content', 10, 2);
add_action('manage_pages_custom_column', 'custom_id_column_content', 10, 2);

Comments

Add a Comment