Blog

A Guide to Custom Gutenberg Blocks

Written by Tarhe on
Woman sitting holding a tablet with cup of coffee on top of table and man smiling behind looking at tablet screen

In case you’re late to the WordPress party, blocks are in.

WordPress continues to evolve and improve the Gutenberg experience, which leads many developers to ask if they should create custom Gutenberg Blocks.

In this post, we look at how custom blocks work, when to use them, alternative options for building your website, and how to build Gutenberg blocks.

What Are Custom Gutenberg Blocks?

Blocks are the basic unit for building pages and posts in WordPress. WordPress introduced blocks with the Gutenberg editing experience in 2018. WordPress includes many default content type blocks, including post titles, images, and galleries. Additionally, plugins also add their own blocks to your editing experience. For example, some of the most recent WooCommerce releases introduced new blocks to make it easier to add products and eCommerce functionality to any page or post in WordPress.

Creating a custom Gutenberg block enables you to utilize that block on any page or post on your site. For example, you could create a block that pulled and displayed customer testimonials.

24/7 WordPress Support

from real WordPress experts

LEARN MORE

If you’ve been reluctant to fully embrace blocks, you’re missing out. All of the latest WordPress features focus on improving the block editor experience. You’ll need to use blocks to take advantage of many of the recent and upcoming WordPress features.

Download our e-book on getting started with Full Site Editing to learn more about how you can use blocks to build and edit your entire site.

When to Use Custom Gutenberg Blocks

You can create a custom Gutenberg block when the existing block options don’t fit your needs and you can’t find a viable alternative with your plugins or themes.

Creating a custom Gutenberg block is usually not a beginner-friendly project. The two most common reasons to code your own custom Gutenberg blocks are when you’re developing a plugin or creating your own theme.

Building a block isn’t a project most people undertake for a single website unless it’s an enterprise-level project with a dedicated developer or development team. We’re sharing some alternative methods that may work better if you need a custom block for only one site.

Alternatives to Using Custom Gutenberg Blocks

Before you go through all the work of figuring out custom blocks, consider if one of these alternatives might work for you.

Block Patterns or Reusable Blocks

If you don’t need to pull in dynamic content and really just want a block to replicate a layout, use the new Block Patterns feature or Reusable Blocks instead. This option is beginner-friendly and can be accomplished with little to no code writing.

Patterns are like a mini-template you can use anywhere on your site. You can insert it onto a page and then edit it. Reusable blocks work in a similar way. The big difference is how they’re treated after you use them on a page or post.

A pattern is a starting point. Once it’s on a page, any modifications you make are unique to that page. If you change the pattern later on, it won’t change where it was already in use.

Reusable Blocks remain linked to one another. If you update the block, the changes will apply to every place you used that block.

Code Block

Use the code block to insert custom code on the page. Theme and plugin developers create custom blocks to use across multiple sites. If you’re working on a single site, you can probably accomplish the same goal in less time by adding a custom snippet of code. Both options require the same level of technical expertise.

The one case where it may be worth considering building your own custom block is if you’re a developer who wants to turn the site over to a client. The client might be able to work with your custom block utilizing the Gutenberg editor but would be totally lost trying to edit your code.

How to Create a Custom Gutenberg Block

You have two options for creating a custom Gutenberg block. You can code it yourself or use a block-creating plugin. Both options require some coding. You’ll want to brush up on web development basics before you give it a try.

Coding It Yourself

Building custom blocks requires development experience. If you like to stick to WYSIWIG editors and your heart races anytime you accidentally click on the show code option, this is not for you.

Creating custom blocks requires intermediate knowledge of HTML, CSS, JavaScript, and React.

Start by setting up your development environment and tools. You’ll need a WordPress environment, Node, NPM, and a code editor. After that, follow this tutorial on creating your first block from the official WordPress block editor handbook.

Using a Plugin

If you’re comfortable with HTML, CSS, and JavaScript but not ready to code everything from scratch, consider the plugin approach. Using a plugin to create custom blocks is a great option when you need a custom block for use on a single website.

The Genesis Custom Blocks plugin is the most popular plugin for creating custom blocks. You’ll create the block fields using the familiar WordPress interface. After setting up the fields, you’ll need to supply the template of HTML, CSS, JavaScript, and PHP to make the block work.

Even though it’s easier, it still requires some coding. The difference is you can do it all from your WordPress admin without setting up a local dev environment. The plugin also makes it easier to test and preview the block to make sure it’s working properly.

Whatever You’re Building, We Can Help

No matter how you build your site, with custom blocks, or if you’re a holdout still using the classic editor, you need a reliable host. Pressable is proud to be the place where WordPress works best for everyone from the solopreneur to the team of advanced developers.

Pressable offers an easy-to-use interface, top-of-the-line security, and blazing-fast speeds. With Pressable’s hosting, your site will be easy to update and simple for your customers to find and use.

Sign up today and start building your site or learn more about transferring an existing site. We’re happy to help you migrate your sites!

Web Performance

Load time matters! Do you know how fast your site is?

LEARN MORE

Tarhe

Obatarhe is a Customer Support Engineer at Pressable, WordPress Enthusiast, Community Volunteer, and Tech Advocate. He gets to do exciting things everyday, these include providing 5 star rated support to customers and rendering tailored service to resolve their issues. When he's not working, you can find him traveling and taking good landscape pictures.