Skip to content

Instantly share code, notes, and snippets.

@krstivoja
Created December 27, 2022 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krstivoja/c9968f6998712f6a35f62ce6bb6f7fb1 to your computer and use it in GitHub Desktop.
Save krstivoja/c9968f6998712f6a35f62ce6bb6f7fb1 to your computer and use it in GitHub Desktop.
Gutenberg ACF Condition Block
<?php if ( !empty(get_field('condition')) ): // Check if condition is applied ?>
<?php // Display if condition is valid
$condition = get_field('condition');
if(eval("return $condition;")): ?>
<InnerBlocks />
<?php else: // If condition is not valid display message ?>
<h2><?php the_field('message'); ?></h2>
<?php endif; // end of if field_name logic ?>
<?php else: // If condition is not set display content ?>
<InnerBlocks />
<?php endif; // end of if field_name logic ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment