From the course: WordPress: Advanced Custom Fields

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Defining your block in code

Defining your block in code - WordPress Tutorial

From the course: WordPress: Advanced Custom Fields

Start my 1-month free trial

Defining your block in code

- [Instructor] An advanced custom field gives us the ability to create blocks for our WordPress editor without the need to learn React, which is how we would natively write blocks. Instead, we're going to add a few php files to our child theme. Starting with the block definition. Now in most cases, I recommend code that has to do with the content get added to a plugin. But since most of this code has to do with the display, and we want to keep everything together, we'll add these files to our child theme. First, let's go ahead and open our functions.php file. We're going to add an action to acf/init. This is essentially acf's version of WordPress's default init action, and it says run this function as soon as acf is initiated. Then we'll add our callback function. We'll call this lil_define_block. We're going to prefix all of our functions with lil. Then we'll add the function. Lil_define_block, and the first thing we're going to do after we add our function is check to see if the…

Contents