Creating your own blocks in Gutenberg with ACF

View in another language:
Creating your own blocks in Gutenberg with ACF
Categories
Technologies
Author

Guy Outsourcify

Wordpress Web Developer
Date

Making your own blocks is one of the nice features of the new WordPress Gutenberg editor that was introduced in late 2018. You can check a live example of what it does here : https://wordpress.org/gutenberg/

The Gutenberg Editor replaced the previous WordPress content editor (now called Classic Editor) which was a classic TinyMCE textarea field with added buttons to format the content, a bit like in MS Word.

Gutenberg introduces a new page builder-like concept, the content field of every page or post is in fact a collection of individual blocks that can be arranged as the content writer wants. It’s much more simple than most page builders, these blocks are headings, paragraphs, lists, images, quotes etc. The number of pre-built blocks is limited and that’s a good thing as hopefully it also allows you to create custom blocks of content.

There are different ways to create your own blocks, our favored technique at Outsourcify is to use the ACF plugin. Beware though you need to install ACF Pro to support Gutenberg blocks.

Creating a block is a bit like creating a plugin and all the code below for all custom blocks used by a website could actually be included in a custom plugin. It can also be done directly in the theme, with most of the magic happening in the functions.php file. It’s relatively simple, you need to register the block, create a field group with all fields that would be needed for the block (could be author and citation for a quote for example), and then create the PHP template file to render the block.

Here for the purpose of the example we will create a very simple block that displays a text inside a rounded blue box.

Register a block

The acf_register_block() function is used for creating the block. You can use this function to customize the details of the block including a name, title, description, icon or more.

Function.php:

add_action('acf/init', 'my_acf_init');
function my_acf_init() {
    // check function exists
    if( function_exists('acf_register_block') ) {
    	// register a testimonial block
    	acf_register_block(array(
            'name'              => 'content-theme',
            'title'             => __('Content with theme color'),
            'description'       => __('A custom content with theme color block.'),
            'render_callback'   => 'my_acf_block_render_callback',
            'category'          => 'formatting',
            'icon'              => 'format-aside',
            'Keywords'          => array( 'content-theme', 'theme'),
       ));
    }
}

Create a field group

After you have registered the block, you can now see it in the ACF plugin page and create all of the fields you want.

From the location rules, you must select “Block” and choose the block you have registered. Now those custom fields are associated to the block.

Render the block

Finally, you’ll need to call your template to render the block and then create your template with HTML and PHP.

Function.php:

function my_acf_block_render_callback( $block ) {
// convert name ("acf/content-theme") into path friendly slug ("content-theme")
 $slug = str_replace('acf/', '', $block['name']);
//Add template path of template(.php file) on your folder.
   if( file_exists(
get_theme_file_path("/templates/blocks/block-{$slug}.php") ) ) {
include( get_theme_file_path("/templates/blocks/block-{$slug}.php") );
    }
}

Block-content-theme.php

<?php
/**
* Block Name: Content with theme color
*
* This is the template that displays the content theme block.
*/

?>
<div class="content-theme">
<div class="title">
  <?php the_field('theme_title'); ?>
</div>
<div class="content">
  <?php the_field('theme_desc'); ?>
</div>
</div>

Adding the block in the editor

That’s it you can now use your block in the editor.

You have 2 different modes: the editor and preview modes. The preview mode requires that you import the frontend CSS file in order to display the block the way you planned it.

Editor mode

Preview mode

This function is used to import your theme CSS. It’ll display the theme css from the front-end in the back-end for preview purposes.

Function.php:

function acf_block_style() {
    wp_enqueue_style('admin-blocks', get_template_directory_uri() .'/css/main.min.css');
}
add_action( 'admin_enqueue_scripts', 'acf_block_style' );

Main.min.css:

.content-theme .content-theme__title {
 font-size: 40px;
 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
 font-weight: bold; }

.content-theme .content-theme__desc {
 margin-top: 20px;
 padding: 30px;
 border: 3px solid #1CAAF5;
 color: #2F077B;
 border-radius: 15px; }

So now the block here looks like it should :

And it should look the same on the website’s frontend.

Guy Outsourcify · Wordpress Web Developer

Guy is a Wordpress custom theme PHP developer and HTML/CSS integration expert, with skills in responsive web design and custom animations using Javascript, the GSAP library for example. She started as an intern at Outsourcify years ago and has been working full time at Outsourcify since.

Have a project in mind?
Let's start your project today

Contact Us
Have a project in mind?
Let's start your project today

Related blog articles

Technologies

Building AcadAsia: A Technical Deep Dive into Thailand’s International School Advisory Platform

February 11, 2026

Building AcadAsia: A Technical Deep Dive into Thailand’s International School Advisory Platform
Building AcadAsia: A Technical Deep Dive into Thailand’s International School Advisory Platform
Technologies

How to Choose the Right WordPress Agency: Beyond the Sales Pitch

January 20, 2026

How to Choose the Right WordPress Agency: Beyond the Sales Pitch
How to Choose the Right WordPress Agency: Beyond the Sales Pitch
Technologies

Our Headless WordPress Journey with Astro.js and Vue.js

September 2, 2025

Our Headless WordPress Journey with Astro.js and Vue.js
Our Headless WordPress Journey with Astro.js and Vue.js
Technologies

Will AI Replace Developers? A Reality Check From the Field

March 11, 2026

Will AI Replace Developers? A Reality Check From the Field
Will AI Replace Developers? A Reality Check From the Field
Technologies

Teaching AI and Software Development at Chulalongkorn University: A Two-Hour Conversation That Went Well Beyond the Slides

February 23, 2026

Teaching AI and Software Development at Chulalongkorn University: A Two-Hour Conversation That Went Well Beyond the Slides
Teaching AI and Software Development at Chulalongkorn University: A Two-Hour Conversation That Went Well Beyond the Slides
Technologies

Skipping Figma Doesn’t Mean Skipping Design

February 18, 2026

Skipping Figma Doesn’t Mean Skipping Design
Skipping Figma Doesn’t Mean Skipping Design
Technologies

Vibe Coding Rescue: From MVP to Scalable Platform

February 15, 2026

Vibe Coding Rescue: From MVP to Scalable Platform
Vibe Coding Rescue: From MVP to Scalable Platform
Technologies

Astro Joins Cloudflare: The New Standard for High-Performance Web Architecture

December 14, 2025

Astro Joins Cloudflare: The New Standard for High-Performance Web Architecture
Astro Joins Cloudflare: The New Standard for High-Performance Web Architecture
Technologies

WooCommerce vs Shopify: Which Platform Fits Your Project?

November 21, 2025

WooCommerce vs Shopify: Which Platform Fits Your Project?
WooCommerce vs Shopify: Which Platform Fits Your Project?
Resources

Building a B2B Product: Laying the Right Foundations from Day One

September 29, 2025

Building a B2B Product: Laying the Right Foundations from Day One
Building a B2B Product: Laying the Right Foundations from Day One
Technologies

A ResTech MVP in 1 Month

September 19, 2025

A ResTech MVP in 1 Month
A ResTech MVP in 1 Month
Resources

Why Taking Over a Development Project Is Always a Challenge

August 11, 2025

Why Taking Over a Development Project Is Always a Challenge
Why Taking Over a Development Project Is Always a Challenge
Technologies

From Vibe-Coded Prototype to Production-Ready: How Client Mockups Accelerate Our Work

August 5, 2025

From Vibe-Coded Prototype to Production-Ready: How Client Mockups Accelerate Our Work
From Vibe-Coded Prototype to Production-Ready: How Client Mockups Accelerate Our Work
Technologies

Outsourcify’s 2025 Tech Stack Driving Digital Excellence

August 4, 2025

Outsourcify’s 2025 Tech Stack Driving Digital Excellence
Outsourcify’s 2025 Tech Stack Driving Digital Excellence
Outsourcify Story

What Our Clients Say About Us: A Look at Outsourcify’s Google Reviews

July 30, 2025

What Our Clients Say About Us: A Look at Outsourcify’s Google Reviews
What Our Clients Say About Us: A Look at Outsourcify’s Google Reviews
Outsourcify Story

The Agency Developer: Beyond the Code

July 14, 2025

The Agency Developer: Beyond the Code
The Agency Developer: Beyond the Code
Resources

A Website Is Non-Negotiable in 2025 — But Its Content May Be Training AI

July 9, 2025

A Website Is Non-Negotiable in 2025 — But Its Content May Be Training AI
A Website Is Non-Negotiable in 2025 — But Its Content May Be Training AI
Resources

SaaS Tools Annual Cost Comparison for a 35-User Team – and What You Can Learn from Our Journey

June 11, 2025

SaaS Tools Annual Cost Comparison for a 35-User Team – and What You Can Learn from Our Journey
SaaS Tools Annual Cost Comparison for a 35-User Team – and What You Can Learn from Our Journey
Technologies

Recent Projects at Outsourcify: A Behind-the-Scenes Series

June 2, 2025

Recent Projects at Outsourcify: A Behind-the-Scenes Series
Recent Projects at Outsourcify: A Behind-the-Scenes Series
Resources

A Guide to Thailand’s Online Payment Gateways

May 4, 2025

A Guide to Thailand’s Online Payment Gateways
A Guide to Thailand’s Online Payment Gateways
Technologies

10 Programming Practices Worth Rethinking

April 29, 2025

10 Programming Practices Worth Rethinking
10 Programming Practices Worth Rethinking
Outsourcify Story

The Outsourcify Story #1: Lessons from a decade in Web Development

March 23, 2025

The Outsourcify Story #1: Lessons from a decade in Web Development
The Outsourcify Story #1: Lessons from a decade in Web Development
Technologies

Outsourcify partners with Sisense: the Power of Business Intelligence

February 16, 2025

Outsourcify partners with Sisense: the Power of Business Intelligence
Outsourcify partners with Sisense: the Power of Business Intelligence
Technologies

The 8 Archetypes of Software Engineers Every Team Needs (And How to Harness Their Superpowers)

February 6, 2025

The 8 Archetypes of Software Engineers Every Team Needs (And How to Harness Their Superpowers)
The 8 Archetypes of Software Engineers Every Team Needs (And How to Harness Their Superpowers)
Outsourcify Website

Eco-friendly and Accessible Websites: Building a Sustainable Digital Future

December 10, 2024

Eco-friendly and Accessible Websites: Building a Sustainable Digital Future
Eco-friendly and Accessible Websites: Building a Sustainable Digital Future
Technologies

The impact of API-centric approaches on software development

November 27, 2024

The impact of API-centric approaches on software development
The impact of API-centric approaches on software development
Technologies

How to know you can trust a web agency: A practical guide

November 15, 2024

How to know you can trust a web agency: A practical guide
How to know you can trust a web agency: A practical guide
Technologies

Who’s watching? A guide to privacy on websites and protecting your data

November 14, 2024

Who’s watching? A guide to privacy on websites and protecting your data
Who’s watching? A guide to privacy on websites and protecting your data
Technologies

Understanding the differences between MVP and MMP for smarter product development

November 13, 2024

Understanding the differences between MVP and MMP for smarter product development
Understanding the differences between MVP and MMP for smarter product development
Technologies

The top 3 strategic pitfalls that can derail a tech startup

November 8, 2024

The top 3 strategic pitfalls that can derail a tech startup
The top 3 strategic pitfalls that can derail a tech startup
Technologies

How to avoid AI project failures: lessons from automation

November 7, 2024

How to avoid AI project failures: lessons from automation
How to avoid AI project failures: lessons from automation
Technologies

The top 3 pitfalls facing CTOs and how to overcome them

October 31, 2024

The top 3 pitfalls facing CTOs and how to overcome them
The top 3 pitfalls facing CTOs and how to overcome them
Technologies

How do we extract the needs of a startup in the context of a Define Scope – Requirements Workshop?

October 29, 2024

How do we extract the needs of a startup in the context of a Define Scope – Requirements Workshop?
How do we extract the needs of a startup in the context of a Define Scope – Requirements Workshop?
Technologies

The vital role of a product owner in your web project

October 25, 2024

The vital role of a product owner in your web project
The vital role of a product owner in your web project
Technologies

How to choose a web agency: Top platforms to help you find a reliable partner

October 15, 2024

How to choose a web agency: Top platforms to help you find a reliable partner
How to choose a web agency: Top platforms to help you find a reliable partner
Technologies

The breadth of expertise required for Web Development

October 9, 2024

The breadth of expertise required for Web Development
The breadth of expertise required for Web Development
Technologies

Running daily, a day early: cron jobs for everyone

October 7, 2024

Running daily, a day early: cron jobs for everyone
Running daily, a day early: cron jobs for everyone
Company Activities

Behind the scenes: Triple baby party & reflecting on our company’s sociology

October 4, 2024

Behind the scenes: Triple baby party & reflecting on our company’s sociology
Behind the scenes: Triple baby party & reflecting on our company’s sociology
Technologies

Caching: Our number one suspect

August 9, 2024

Caching: Our number one suspect
Caching: Our number one suspect
Technologies

What is a database and how do you choose one for your web application project?

June 18, 2024

What is a database and how do you choose one for your web application project?
What is a database and how do you choose one for your web application project?
Technologies

Outsourcify’s expertise with the Astro framework

June 11, 2024

Outsourcify’s expertise with the Astro framework
Outsourcify’s expertise with the Astro framework
Technologies

What is an API and how does Outsourcify use them?

May 22, 2024

What is an API and how does Outsourcify use them?
What is an API and how does Outsourcify use them?
Technologies

Which LLMs are we using to facilitate the development at Outsourcify?

May 10, 2024

Which LLMs are we using to facilitate the development at Outsourcify?
Which LLMs are we using to facilitate the development at Outsourcify?
Technologies

Integrating an AI service for Real Estate

January 19, 2024

Integrating an AI service for Real Estate
Integrating an AI service for Real Estate
Technologies

User Interface(UI) design process, before & after.

January 14, 2021

User Interface(UI) design process, before & after.
User Interface(UI) design process, before & after.
Technologies

Why and how to migrate from Drupal to WordPress?

November 13, 2020

Why and how to migrate from Drupal to WordPress?
Why and how to migrate from Drupal to WordPress?
Resources

How to achieve 100 on PageSpeed Insights

May 3, 2019

How to achieve 100 on PageSpeed Insights
How to achieve 100 on PageSpeed Insights
Outsourcify Website

Why would you use WordPress for a corporate website in 2019?

March 17, 2019

Why would you use WordPress for a corporate website in 2019?
Why would you use WordPress for a corporate website in 2019?
Technologies

How will the new version 5 and the Gutenberg editor impact your WordPress website?

December 5, 2018

How will the new version 5 and the Gutenberg editor impact your WordPress website?
How will the new version 5 and the Gutenberg editor impact your WordPress website?
Technologies

How to search in ACF’s Custom Fields in WordPress

September 4, 2018

How to search in ACF’s Custom Fields in WordPress
How to search in ACF’s Custom Fields in WordPress