Use a reusable block in your theme

I ran into a situation where I created a reuseable block for many of the content pages of an e-commerce site. We wanted to use this same block at the bottom of all WooCommerce product pages as well. I could have written custom HTML/CSS for this small banner block but I always love making things editable in a single spot.

Reuseable blocks are saved as Custom Post Types in WordPress. As such, there is an admin page where you can find them. When adding/editing a page, click the “+” used to add a new block, click the “Reusable” tab, then click “Manage all reusable blocks”.

Click on the block you want to include in your theme files to get the unique post ID. Example: https://yourdomain.com/wp-admin/post.php?post=123&action=edit

In your theme template file, use the following code:

$block = get_post( 123 ); // Change 123 to the unique post ID for your block
echo apply_filters( 'the_content', $block->post_content );
About the Author
Derek Ashauer is the sole developer at WP Sunshine. He also does client work through his agency AshWebStudio where he has been working with WordPress since 2005.