When I create settings for Posts, Pages or any custom post type, I always use Gutenberg plugin sidebars. But the thing is that sometimes you do not want to create a separate sidebar for every post type, you’d rather prefer to display some panels (or even fields) for one post type and the other panels for another one.
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.
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.
Now it is time to add some block settings into the sidebar. Here is what I mean:
So we are going to have a couple of options for your block, their values will become the hidden field values of the subscription form on the website which the block displays.