Should Gutenberg blocks be in plugins or themes?

Gutenberg is still going through the finishing stages before it’s released in WordPress core. But there’s still a question about Gutenberg blocks that I’m not really seeing anyone answer.

Where should blocks be placed: plugins or themes?

Now admittedly the team has a lot bigger issues to deal with right now. And my focus is heightened on this issue because the “plugins and themes should be separate” hill is one I’m willing to die on in WordPress.

But as Gutenberg gets closer to being released, this is something we need to be thinking about. Coming up with a clear, uniform policy will help users, and even developers, continue to use WordPress effectively. It’s the difference between easy transitions and losing everything on a site.

So which one should it be?

Why this matters

This matters because it could be a problem for end users down the road. If it isn’t done right, users could end up losing blocks unexpectedly if they make a change to their site’s theme.

Per WordPress itself, themes are for the design of the website, nothing more. If you try to submit a theme to the directory and it adds functionality, like a custom post type or taxonomy, it will be rejected. Meanwhile, plugins add that functionality to the site.

And it’s with all good reason. If I switch a theme, I’m expecting that I’m going to have to change the homepage again to set it up. But I’m not expecting to no longer have access to custom post types or taxonomies or even shortcodes (which is what the blocks most resemble).

The same goes with blocks. If they’re placed in the wrong compartment, so to speak, and a user makes a change and then suddenly loses a block they weren’t expecting too, they’re going to be frustrated. And nobody wants that.

That’s the situation we, as developers, need to avoid.

Case for blocks in plugins

People change their themes much more often than they remove a plugin and replace it with another one that does similar functionality. Sure, you might go through this process when you’re first creating a site and trying to figure out what works the best. But once you find the right one, you use that for practically forever.

Because of that, plugins make for excellent hosts for Gutenberg blocks. Users aren’t going to change them out all that often. And if they do remove a plugin, they know, or at least they should know, that they’re going to lose that block. Otherwise, that plugin just sits on their site doing its job and they don’t need to worry about losing that functionality.

Case for blocks in themes

Now I do think there are situations where placing blocks in themes is a good solution. Like many “rules” on the web, there are always exceptions.

The main scenario I’m think of is with a homepage. Obviously, a theme creators develop a specific look for a homepage. So any blocks that should be used on the homepage of a theme should be packaged with that theme. Users should then know that they will lose those block when they change themes.

Other scenarios include any blocks that deal with specific page templates or anything else that’s theme specific. If it deals with the theme and won’t stand without, then it’s okay to package it with the theme.

Conclusion

So, what’s the best policy for all of WordPress when it comes to Gutenberg blocks? Well, I don’t know.

One of the best parts of the WordPress is the community aspect. And the community is the one that collectively comes up with the guidelines. And I suspect there will be discussions about it and some sort of agreement will be made.

As for what my policy will be with my development, that’s pretty easy. All blocks will be placed in a plugin, unless it specifically deals with a theme element. I still think that themes should limit the functionality they add since that’s not their role in WordPress. That’s a job for plugins.

And if you’re creating a theme that has functionality and want to follow the correct way of doing things, I highly recommend creating a functionality plugin for the theme. This works for themes going in the WordPress repo or somewhere else to be sold.

But when you’re creating blocks, remember: themes are for design, plugins are for functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.