How to Use Custom Callback to Display Image in the Admin Columns
This tutorial will teach you to use a custom callback to display information from the meta fields in admin columns within custom post type lists created with the JetEngine WordPress plugin.
Before you start check tutorial requirements:
Elementor (Free version) or Block editor (Gutenberg)
JetEngine plugin installed and activated with Custom Post Type created and several posts added. If you have not done this yet, please follow this tutorial
It is possible to display the content from the meta fields in admin columns with the help of a custom callback function provided by the JetEngine plugin.
Let’s assume you need to display the picture from the Media meta field in the custom type posts list. This tutorial will show you how to do it.
Add the Code
Open the file manager on your PC and find the folder with WordPress files. Proceed to wp-content > themes and open the folder with the theme you currently use.
Use the Notepad app to open the functions.php file and insert the following code:
It is a specialized piece for image insertion. Pay attention that instead of “_image,” you have to insert the meta field name from which you want to take the picture.
Add a New Admin Column
Go to the WordPress Dashboard and open the JetEngine > Post Types tab. Click on the needed post type to edit it.
Define the Admin Column Settings
When the settings block opens, scroll down to Admin Columns and click the “Add New” button.
Now it is time to go through the column settings:
- Title — choose the column name displayed in the content type posts list;
- Type — select the “Custom Callback” option;
- Callback — insert the callback function name here;
- Column Order — type in the value that will define the number of the column’s order;
- Prefix and Suffix — set the text placed before or after the data in the column;
- Is Sortable — enable this toggle if you want to make the column sortable.
Update the Post Type
Finally, click the “Update Post Type” button and go to the custom post type on the WordPress Dashboard to view a new Image admin column.
Now you know how to display the data from the meta fields, media files, in particular, using the JetEngine callback option.