How to Create Templates with Reusable Blocks in WordPress?
WordPress introduced Gutenberg block editor with the version 5.0. You can insert from the set of available blocks and create content on the post editor. In addition, Gutenberg also allows you to create reusable blocks that you can insert anywhere on your site globally. However, many users do not aware that you can easily create templates using reusable blocks and update the content on each post. In this article, we will explain how to create templates with reusable blocks in WordPress.
Create Reusable Blocks
You can check out our earlier article on how to manage reusable blocks in Gutenberg editor. Here are the summary of steps to create reusable blocks:
- Make sure you have Gutenberg editor enabled for creating posts. This is a default settings unless you have installed Classic Editor plugin.
- Go to “Posts > Add New” menu to open Gutenberg block editor.
- You don’t need to give any title. Just click on the + icon and add a “Heading” block.
- Add a placeholder text inside heading like “This is a first heading”.
- Click on the three dots options button and select “Add to Reusable blocks”.
- Provide a name for your block like “Reusable Template 1” and save your block.
Remember, you do not need to publish your post for creating a reusable block.
Converting Reusable Block into a Template
Now that you have simply created a single heading element as a reusable block. The next step is to add more elements to the reusable blocks to create a template.
- Click on the ⊕ icon on top right corner of the editor.
- Scroll down to the “Reusable” section and click on the “Manage all reusable blocks” link.
- WordPress will prompt you to confirm leaving the post editor as you did not save the post content. Click on “Leave” button to confirm exiting.
- This will take you to the hidden reusable blocks section where you can view all previously created reusable blocks on your site.
- WordPress saves reusable blocks as a “wp_block” custom post type. This essentially means your reusable block is a post that can contain different block elements like regular post or page on your site.
- Hove your mouse over the reusable block you have create “Reusable Template 1” and click on “Edit” link.
- This will take you to back to Gutenberg editor where you can add elements to your template.
Adding Elements to Template
Similar to adding blocks to your normal post, add paragraph, image, media & text, social icons or any other blocks.
When your final template is ready, click on the “Update” button to save the reusable block. Now, your template with placeholder blocks is ready for reuse.
Inserting Template and Editing Content
Whenever, you want to insert your “Reusable Template 1” to your post or page, click on the + icon and insert the block from “Reusable” section. In order to edit the template, click on the three dots button and choose “Convert to Regular Block” option.
This will convert the reusable template into a normal block and break each element into an editable block. You can update the placeholders with real text and images and publish the post.
You can reuse the template as many as times and publish posts quickly instead of creating each post from scratch.
Alternate Option Using Group
If the above method is lengthy for you, there is an alternative option available for you.
- Create a new dummy post and add blocks for creating your template.
- Select all the blocks you want to include in the template either by dragging the mouse or using shift key and choose “Group”.
- Now, click on the three dots button and choose “Add to Reusable blocks”.
- Provide a name like “Reusable Template 2” and click “Save” button to save your reusable block.
You can insert this reusable group block anywhere on the site and convert to regular block for editing.
You can customize each element in the template like changing the text color or adding a background. This will be super useful when you create multiple posts that looks similar. It saves plenty of time to use reusable templates, otherwise you may need to create each post and customize each element independently. Gutenberg has great potential to throw all your page builder plugins to trash. Since, it is part of WordPress core give it a try to create reusable templates and probably you will not turn back to any third-party plugins.