Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/WP/Block Lab

January 1, 2019

Block Lab

Block Lab is a plugin that allows you to create custom blocks within the WordPress Gutenberg editor. You can create blocks for content or code that you repeatedly use in an effort to simplify publishing. To create a custom plugin, you will need to create a block first. Once you named a block, you can add fields to that block and pass the variables to the block templates. The template contains the code that you need to send to the Gutenberg editor in the form of blocks. Here’s an example of a Block and Template.

My Custom Block

Custom block

Template: block-my-custom-block.php

The “block_field” function echoes the variables passed from the blocks to the template.

<h4><?php block_field( 'heading' )?></h4>

<h4><?php block_field( 'heading' )?></h4>

In some instances, you may have to mute the echo. In this example, I’m using the function in a comparison.

<h4><?php if (block_field( 'heading', $echo = false ) == ""):
 else: block_field( 'heading' ); endif; ?></h4>

<h4><?php if (block_field( 'heading', $echo = false ) == ""): else: block_field( 'heading' ); endif; ?></h4>

Filed Under: WP Tagged With: block lab, custom blocks, gutenberg

Content delivered to your email

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021