Home/ Documentation/ WordPress/ Blocks/ Theme or Plugin – Which is Best for Custom Blocks?

Theme or Plugin – Which is Best for Custom Blocks?

Where to define our custom blocks? In a theme or plugin?

Pinegrow WordPress Builder can export both themes and plugins.

That opens the question: where should our blocks be defined? In a theme or a plugin?

The simple approach: theme

The simplest approach is to define blocks in our theme.

Create a WordPress theme project, define blocks and export the theme.

All blocks will be available in the block editor.

We can easily use the Theme settings to include any framework stylesheets into the backend block editor.

But, this simplicity comes with limitations. Our blocks are tied to this one particular theme.

Reusable blocks: plugin

What if we want to create a library of reusable blocks that we can use in multiple projects?

What if we want to add custom blocks without changing the theme? The theme might not even be made with Pinegrow.

In such cases, we can create a WordPress plugin project, define blocks and export them as a plugin that we can activate on any website.

With plugins, we are not able to include framework stylesheets into the block editor. That makes sense, because framework (or global website styles) is something that is defined by the active theme, not a plugin.

Mix: theme and plugins

Of course, we can freely match themes and plugins. This is the most flexible solution.

We create themes that contain website styling and defines the blocks that are specific to the theme.

And, we create plugins that implement reusable block libraries. We can then activate these plugins on any website where we need them.

Of course, the theme and plugin framework should match. Block plugins should use Bootstrap, if the theme is using Bootstrap. The same is true for Tailwind CSS and any other framework.

That said, we can also create plain HTML blocks that implement their own CSS styling and use them in any project regardless of the theme framework.



Last updated on November 16, 2021 at 10:09 pm


Print this article