In this tutorial, we will add 2 extra fields to the page object:
- Page Image: An image field (we can show this as a thumbnail in the column)
- Featured: A true / false field (we can filter the pages via this field)
1. Add extra page fields
Using the Advanced Custom Fields Plugin, add a new ACF group with the 2 fields. Note: The image field needs to save the attachment ID so we can easily retrieve the thumbnail version for the column.
2. Add a sprinkle of code
Now that our pages have extra fields, let’s add in the code to show the fields in the page’s columns. The 2 functions bellow hook into WordPress and override the column creation process. the “my_page_columns” function overrides what the columns are and the “my_custom_columns” function tells WordPress what to do with the columns.
This is what your page columns should look like
3. And a pinch of salt: Sortable Columns
To finish of this tutorial, lets now allow the featured column to be sortable. This can be a very useful feature when working with lots of page / post objects.
I hope you enjoyed this simple but useful tutorial. We covered some advanced WordPress & PHP techniques and created an attractive and user friendly admin edit page. Be sure to tweet about this article, thanks for reading.