Add comment_id on Comments page within wp-admin

In the backend of WordPress, on the Comments page. Is possible to include a column for comment_id? Here is a visual of the locaton…

Add comment_id on Comments page within wp-admin

…perhaps to the left of the Comment column? If so, what would be an efficient way of doing that?

or if easier, under the 127.0.0.1 for each comment? Either way, I just need a visual because that number will be significant in what my non-technical client needs in another task.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Is possible to include a column for comment_id?

Yes, and there are two hooks that you’d want to use:

Working example you can try:

// Add the comment ID column.
add_filter( 'manage_edit-comments_columns', function ( $columns ) {
    $columns['comment_id'] = 'ID';
    return $columns;
} );

// Display the content of the above column.
add_action( 'manage_comments_custom_column', function ( $column_name, $comment_ID ) {
    if ( 'comment_id' === $column_name ) {
        echo $comment_ID;
    }
}, 10, 2 );

Additionally, if I were you, I’d probably want to make the comment ID column be sortable (so that the comments list can be sorted by clicking on the “ID” column in the table header/footer), and for that, you can use the manage_edit-comments_sortable_columns hook to add the column to the sortable columns list:

add_filter( 'manage_edit-comments_sortable_columns', function ( $columns ) {
    $columns['comment_id'] = 'comment_id';
    return $columns;
} );

Note that the comment_id doesn’t need extra coding to make the comments sorting works, so you could simply add the column to the sortable columns list — for other custom columns, you may need to write the code for sorting the comments based on the specific custom column.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x