The block_field() function outputs the value of a field you have created with Block Lab.

block_field( $name, $echo = true );

Note: If the supplied $name doesn’t exist, block_field() will return null.


  • $name (string) (Required) The field name
  • $echo (bool) (Optional) Whether the value should be formatted and output, or returned as a variable.


In this example, display the value of a field as text in your template.

<p><?php block_field( 'testimonial' ); ?></p>

In this example, return the value of a field for further use without displaying it.

$author_name = block_field( 'author', false );

In this example, check to see if the value of the field is set.

$url = block_field( 'url', false );

if ( ! empty( $url ) ) {
    echo '<a href="' . $url . '">Click me!</a>';