How to Remove Pages Columns in WordPress: A Comprehensive Guide

WPTurbo » Snippets » How to Remove Pages Columns in WordPress: A Comprehensive Guide
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking to streamline your website’s administration dashboard by removing unnecessary clutter? One way is by removing page columns that are not being used. This small change can make your WordPress dashboard look a lot cleaner and easier to manage. This article will guide you through the process of removing unused page columns in WordPress, allowing for a more focused and efficient workflow. Let’s simplify your WordPress experience together.

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

The above code snippet is aimed at removing columns from the Pages admin table in WordPress. To break the snippet down, we will first define what the code does in general, then we’ll dissect it to understand its working mechanism.

The function wpturbo_remove_pages_columns($columns) is defined at the beginning. This function will be utilized to manipulate the columns displayed on the Pages admin table.

Here is a closer look at the function:

function wpturbo_remove_pages_columns($columns){
    unset($columns['comments']);
    return $columns;
}

The $columns parameter is an associative array containing all the columns that appear in the Pages admin table. The key name in the array corresponds to the ID of the column, and the value associated with the key is used as the column header.

The unset function in PHP is used to destroy the specified variables. In our code, unset($columns['comments']) removes the item with the key ‘comments’ from the $columns array. We’re essentially deleting the ‘Comments’ column from the Pages admin table.

Towards the end of the function, $columns is returned. This is important – This modified array, now without ‘comments’, provides the new set of columns for the Pages admin table.

Availability of the modified array then leads to the following line of code:

add_filter('manage_pages_columns' , 'wpturbo_remove_pages_columns');

The add_filter function is a WordPress hook that allows you to ‘hook’ your own functionality onto a WordPress function. In this case, the code hooks wpturbo_remove_pages_columns function to manage_pages_columns.

To better understand, 'manage_pages_columns' is a WordPress filter that controls the columns that are displayed on the Pages admin table. By hooking wpturbo_remove_pages_columns function into this filter, the function is passed the $columns array when the filter runs. The function then adjusts the array as needed (in this case, removing the ‘comments’ column), and returns it back to WordPress.

As a result, when the Pages table is displayed in the WordPress admin area, the ‘Comments’ column will be missing, as we have effectively removed it using the above code snippet. It’s a precise customization to create a more streamlined admin area.

Register an account to save your snippets or go Pro to get more features.