The built-in Featured Image Meta Box is an cool feature. We’re so used to it, and we can all agree on that it is truly awesome. But the reality is, it’s very basic, and often feels inflexible. In this post I will show you how to extend the Meta Box functionality by adding Custom Fields to that very same Meta Box, that will be related to controlling the way images are being displayed.
Add Custom Fields
First, we need to add custom fields to the Meta Box. It’s done using the
admin_post_thumbnail_html filter. To demonstrate how easy it is, let’s add a simple checkbox under the image:
Note: The custom field key/name is defined in
Save Custom Fields
Next, you need to sanitize user data and save/update the custom field value accordingly. It’s done using the
Now we have a new checkbox contained within the Featured Image Meta Box. The field is saved as a regular custom field named “
show_featured_image“. It accepts a value of either
This way, content managers have more control over the end result. They can define featured images, for instance, to be used in social media, but not to be displayed in the theme.
Of course you could add different field types. You can, for example, add text fields, select boxes, radio buttons or any other field type you need.
That’s just a simple yet creative way of customizing the “Featured Image” Meta Box.
As always, if you have any comments or questions, be sure to share them with us.