• Skip to primary navigation
  • Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

block lab

Block Lab

by Ulysses · Jan 1, 2019

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

Building A Custom Block

by Ulysses · Dec 26, 2018

I found a new WordPress plugin that allows you to add custom blocks within the Gutenberg editor. You can create any block that you want by using the same templating code you’re already familiar with in WordPress. You can work with CSS, PHP, plugin shortcodes, etc. It’s a beautiful plugin with endless possibilities. The plugin is called Block Lab.

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

Copyright © 2012–2021