As a user sometimes you may want to duplicate certain contents in more than one pages, One way is to manually paste the content everywhere and publish it. But the downside is, If you want to change something in your content then you get the burden of updating the same in every page you have pasted the content previously.
For example, You want to insert a line or two with affiliate links in some of your articles (not all, just few of your articles). You have manually inserted everywhere but then you came to know that the affiliate links needs to be changed. The only option you have now is to update every single page you have inserted the line.
So whats the solution ?
Imagine instead of inserting a line, You insert a short code which displays the content you wish to display and whenever the content changes it automatically reflected to every place you have inserted the short code. Thats what content blocks are all about.
Content blocks are custom post types just like an article or page, You can create a content block with any name and content then it will automatically generate a short code which can be used anywhere in the site to display the content.
Sounds interesting right ? lets implement it with just few steps.
Implementing content blocks
The following steps applicable to any WordPress theme, If you are using theme frameworks (like Genesis, Builder etc) then implement the steps in child theme.
- Download the Zip file and extract it. You will find two files
- Move the
single-blocks.phpto your root folder of your theme. If using Genesis or other frameworks then move it to root folder of the child theme.
- If your theme does not contain a folder called
incthen create one called
blocks.phpfile to that folder.
functions.phpand add the following code right after the
/* Blocks custom post type */ include_once('inc/blocks.php');
Thats it check your WordPress admin area and you will find new post type called “Blocks” in left sidebar.
How to use custom content blocks
- To create a content block go to
WordPress Dashboard >> Blocks >> Add New.
- Name the block and insert the content as you normally do for posts/pages and hit Publish.
- Now go to
WordPress Dashboard >> Blocks >> Blocksand you will find short code for the created blocks. Copy the short code and use wherever ever required.
- Note that you can control the name of short code by editing the block permalink.
Let me know your thoughts about this tutorial in comments section below.