Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
Lessons:15Length:1.2 hours
  • Overview
  • Transcript

2.3 Removing Unnecessary Table Columns

Tables are used throughout the admin UI to display various bits of information about specific elements: posts, pages, comments and so on. The thing is, these tables sometimes show unnecessary columns, which can bloat the interface.

So, let’s see how we can remove them.

Related Links

2.3 Removing Unnecessary Table Columns

Tables are used throughout the admin UI to show various bits of information about different elements, like post, pages, comments, and so on. But, the thing is, sometimes they show some unnecessary columns. For example, if you're not using the comments system, it doesn't make sense to show this column when viewing the post list. So let's see how we can remove some of these columns that we don't actually need. Let's have a look at the articles here. And let's say that we wanna remove the tags and the comments. Well, one way of doing it is from screen options. So, you can see I already unchecked categories here, so I can uncheck tags and comments. But, what if, we wanna remove them completely? Well, it's actually very simple. Let's write a function that's called customize posts listing coles, or columns. And we're gonna pass in columns. And this function, will be tied in, via hook, to manage posts columns. So, first things first, let's actually do a print R of columns, to see what's going on there. And you can see that for each column, we have the title here. So author, title, categories, tags, date and so on. We can do something like this, unset, columns, tags, for example. And then we're gonna return, the new columns. Let's refresh, and now the tags are gone and they're also gone from the screen options here, right? So let's actually remove comments and categories as well, we'll do the same, and now these are gone and they're gone from the screen options as well. And that's it. Very very simple. Now, you can do the same for pages because on pages, you can see that we still have comments here. So if you wanna remove this from pages, you would actually have to write another function. So let's copy this function here. And this is gonna be four pages, so pages list in cols but the idea is the same. You would unset comments, return it, and then we need to add another hook here manage_pages_columns and then customize pages_listing_cols. So now, the comments are gone. And, that's how you remove the table columns you don't need. Now, whenever you're building a WordPress theme, it's always a nice thing to include documentation, so that whoever will be using it, doesn't run into any problems. Fortunately, you can add documentation directly into the admin UI. So, coming up next we'll find out how.

Back to the top