admin管理员组

文章数量:1308138

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

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

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

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

Share Improve this question edited Jan 14, 2021 at 17:44 klewis asked Jan 14, 2021 at 17:38 klewisklewis 8991 gold badge14 silver badges29 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Is possible to include a column for comment_id?

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

  • manage_edit-comments_columns — use this hook to add custom columns to the comments list table, e.g. the custom comment ID column.

  • manage_comments_custom_column — use this hook to display (echo) the content for a custom column added via the above hook.

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.

本文标签: Add commentid on Comments page within wpadmin