0

I know how to remove from pages:

function remove_pages_count_columns($defaults) {
  unset($defaults['comments']);
  return $defaults;
}
add_filter('manage_pages_columns', 'remove_pages_count_columns');

But can't find the answer how to remove for posts.

I have tried:

add_filter('manage_posts_columns', 'remove_posts_count_columns');

and

add_filter('manage_post_columns', 'remove_post_count_columns');

But none of the above worked.

Any help would be appreciated.

1 Answer 1

2

Should be work, if you use the filter manage_posts_columns. The hook is fine, see https://core.trac.wordpress.org/browser/tags/5.8/src/wp-admin/includes/class-wp-posts-list-table.php#L714

Documentation include examples - https://developer.wordpress.org/reference/hooks/manage_posts_columns/

Example:

function remove_posts_columns( $columns, 'post' ) {

    unset( $columns['comments'] );
    return $columns;
}
add_filter( 'manage_posts_columns',  'remove_posts_columns', 10, 2 );
5
  • Hey bueltge, thanks for your effort, but I'm getting an error trying to save this code inside the functions.php: Your PHP code changes were rolled back due to an error on line 101 of file wp-content/themes/simplest/functions.php. Please fix and try saving again. syntax error, unexpected ''post'' (T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE)
    – robert0
    Sep 2, 2021 at 15:20
  • I have removed , 'post' from your code and it worked! Thanks for your help!
    – robert0
    Sep 2, 2021 at 15:30
  • Do you have also the additional parameters on add_filter to trigger that the function have two parameters? It is necessary to inform the hook.
    – bueltge
    Sep 3, 2021 at 8:29
  • second prameter should be $post, a var, not a string
    – Mark
    Jan 18, 2023 at 8:00
  • But in this case it is the post-type, a static value, a string 'post', and not a var that accepts different strings.
    – bueltge
    Jan 18, 2023 at 9:50

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.