1

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...

enter image description here

...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.

1 Answer 1

2

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.

1
  • 1
    had no idea it was so easy. Thank you!
    – klewis
    Commented Jan 15, 2021 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.