From the course: WordPress: Advanced Custom Fields

Unlock the full course today

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

Creating the block template

Creating the block template - WordPress Tutorial

From the course: WordPress: Advanced Custom Fields

Start my 1-month free trial

Creating the block template

- With our call-back function defined it's time to create the template part. In our child theme under the template parts folder, we're going to create a new folder called "block". And inside that folder we'll create a new file called "content-fun-facts.php" This needs to match the name that we used when we registered our block. In our template part, let's start with an opening P-H-P tag and then we will add a single line comment called "Block Name: Fun Facts". The next thing we're going to do is create a new variable called I-D. And this will be the I-D that gets used when the block is rendered. We'll call that fun dash facts dash, and then we'll use the block I-D from the block array that was passed to our call-back function. The last piece of set-up we have here is to create a new variable called "align class". Since every block in the block editor can have a different alignment class, we want to grab that dynamically and associate it with the block. So we'll do that by using a…

Contents