Checkbox

The Checkbox field creates a single checkbox input option for the block.

Screenshot showing the Checkbox block editor

Settings

  • Help Text: Instructions to describe the data needed in the field.
  • Default Value: The default value for this field (checked or unchecked) when adding the block.

PHP API Controls

  • name
  • label
  • control
  • type
  • order
  • location
  • width
  • help
  • default

Template Usage

To display the Checkbox field in your template, use the field name you provided.

<?php block_field( 'housebroken' ); ?>

Example template file /blocks/block-block-lab-example.php

<?php
// Block Lab Example Checkbox Field
?>

<p>Is the pet housebroken?</p>
<p><?php block_field( 'housebroken' ); ?></p> 

To use the block with the Checkbox field on your site, locate it in the blocks menu.

Screenshot showing the Block Lab custom block in the menu

It will then display within your post/page.

Screenshot showing the block displayed in the editor

And on the front-end of your site.

Screenshot showing the block displayed on the web page

The API will return a Boolean with ‘true’ as the default value.

<?php
// Block Lab Example Checkbox Field
?>

<p>Is the pet housebroken?</p>

<?php
if ( block_value( 'housebroken' ) ) {
 echo 'This pet is already housebroken.';
} else {
 echo 'This pet will need some training to become housebroken.';
}
?>