Guides
Display Custom Fields (Meta)
This guide explains how to display and manipulate custom meta fields created with Lazy Blocks in your WordPress theme or plugin.
Custom meta fields are primarily intended for developers. If you're new to custom fields, please review the WordPress Custom Fields documentation first.
Basic Meta Value Display
To display a simple meta value:
PHP
<p>
<?php echo get_lzb_meta('control_meta_name'); ?>
</p>
Working with Meta Values
Conditional Display
PHP
if (get_lzb_meta('control_meta_name')) {
?>
<p>The value is True</p>
<?php
} else {
?>
<p>The value is False</p>
<?php
}
Handling Array Data (e.g., Repeater Fields)
PHP
$repeater = get_lzb_meta('control_meta_name');
foreach ($repeater as $inner_control) {
?>
<p><?php echo esc_html($inner_control); ?></p>
<?php
}
Working with Image Fields
Display image with URL and alt text:
PHP
$image = get_lzb_meta('control_meta_name');
if (isset($image['url'])) : ?>
<img src="<?php echo esc_url($image['url']); ?>"
alt="<?php echo esc_attr($image['alt']); ?>">
<?php endif; ?>
Display image using WordPress attachment functions:
PHP
$image = get_lzb_meta('control_meta_name');
if (isset($image['id'])) {
echo wp_get_attachment_image($image['id'], 'large');
}
Manual Meta Data Handling
When Lazy Blocks plugin is not active but you need to access previously saved meta data, you'll need to manually decode the stored values.
Here's how to manually retrieve and decode meta values:
PHP
// Get raw meta value from database
$meta_val = get_post_meta(get_the_ID(), 'meta_name', true);
if ($meta_val) {
// Decode the stored meta value
$meta_val = json_decode(rawurldecode($meta_val), true);
// Use the decoded value
var_dump($meta_val);
}
The get_lzb_meta()
function automatically handles decoding of stored meta values. Only use the manual decoding method when the plugin is not available.
Previous ArticleInclude Lazy Blocks within theme or pluginNext ArticleCustom Post Type and Save in Meta control