• I want to remove / not display the sortable Post Views column in admin area, for other users except administrator.

    I tried this without results

    add_filter( 'manage_posts_columns', 'custom_pages_columns' );
    function custom_pages_columns( $columns ) {
      unset(
        $columns['post_views']
      );
     
      return $columns;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author dFactory

    (@dfactory)

    Post views columns are applied on per post type basis so you have to remove it the same way:

    add_action( 'admin_init', 'remove_custom_pages_columns' );
    
    // detect post types
    function remove_custom_pages_columns() {
    	// check for administrator
    	if ( ! current_user_can( 'manage_options' ) ) {
    		$post_types = get_post_types( '', 'names' );
    
    		if ( ! empty( $post_types ) ) {
    			foreach ( $post_types as $post_type ) {
    				// apply filter
    				add_filter( "manage_{$post_type}_posts_columns", 'custom_pages_columns' );
    			}
    		}
    	}
    }
    
    // remove columns
    function custom_pages_columns( $columns ) {
    	if ( isset( $columns['post_views'] ) )
    		unset( $columns['post_views'] );
    
    	return $columns;
    }
    Thread Starter AndreiD

    (@andreiro37)

    cool, worked
    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove admin column for user roles’ is closed to new replies.