Metadata

Add Custom Fields to Comments

I already have plenty of tutorials about working with custom fields – a tutorial about creating custom meta boxes for posts, a tutorial about custom taxonomy term fields, a tutorial about options pages and even my own Simple Fields plugin intended to simplify the work with all that stuff. Now it is time to talk about meta boxes for comments.

The long story short let me show you what we are going to create:

create a custom metabox for WordPress comments

It is not a very difficult meta box, but I am just going to show you the process how it works, everything else is up to you. We are going to do it without any plugins first.

Create Beautiful Datepicker Field in WordPress Admin

In this tutorial I will show you how you can easily create a beautiful datepicker field just like on the screenshot below without any additional JavaScript libraries.

create custom datepicker field in user settings

Meta Boxes Conditional Logic

In this tutorial I will explain you how to show or hide a field depending on a value of another field within a simple WordPress metabox.

Like this:

conditional logic in WordPress meta boxes
Show or hide a custom field depending on a value of another field.

Add Custom Fields to a Taxonomy

In this tutorial I will show you step by step how to add a custom field to a custom taxonomy in WordPress. Of course, this method is going to work great for default taxonomies as well.

First of all I will show you how to do it without any plugins and then we will do the same with the help of my Simple Fields plugin, so you can see the difference.

Well, let’s take a look what we are going to create here.

WordPress custom fields in taxonomy
Here I decided to add multiple fields – a simple text field and an image field.

And this is how it looks when you go edit a specific taxonomy term:

add custom fields on edit term pages

Creating Custom Sidebars with PluginSidebar

Creating Gutenberg sidebars and panels with fields inside of them is a brand new way of working with WordPress metadata. I am sure that the default way of creating meta boxes will stay with us for a long time as a backward compatibility, but believe me that working with the content using blocks and sidebars is a much more pleasant way than trying to configure everything in old-fashioned meta boxes.

So, what we are going to do in this tutorial?

Usually I like to show practical examples in my tutorials. And here is the one – I don’t use any SEO plugins on my projects, because I think they are too heavy and bloated with code. But if you’re familiar with SEO, you know that it is important to add unique titles and meta descriptions for your website pages. And probably you would like to hide some of them from indexing with robots meta tag.

create custom Gutenberg plugin sidebars
Our Gutenberg sidebar has 3 fields here – one text field, one textarea field and one toggle.

Please also stay away from tutorials where it is recommended to work directly with WordPress REST API and use wp.apiRequest etc. That’s not a correct way of creating Gutenberg sidebars.

Multiple Image Upload Metabox

I had so many requests about multiple image uploads in comments in this tutorial, so I decided to create a separate tutorial specifically about that.

Our goal is to create something like this:

Multiple image upload metabox
So we can not only select multiple images but even sort or delete them after selection.

Guys, there are actually two ways of creating a meta box like that, the first way is an easy-breezy way, but you have to install my Simple Fields plugin first, the second way – is to do everything manually from scratch. But please do not worry, no matter what method you choose, I am going to cover both of them in this tutorial.

Custom Product Meta

In this tutorial we are going to talk about how to add custom fields to WooCommerce products. I am not going to talk about plugins here – we will work with code snippets only and all the additional fields will be added to “Product Data” metabox.

Please also keep in mind that WooCommerce allows to hide or display specific product fields depending on a product type. So for example we can show our additional product fields only for “Downloadable” or “Variable” products.

Just like that:

WooCommerce custom product meta
As you can see we added a product field into “Advanced” tab, then we created a conditional “Misha” custom tab and added some additional custom product fields there as well.