Hide a block when a field is empty
wp-if="promo-text" A promo banner that disappears when the client clears its text, a photo frame without an empty grey box: the block is printed only when the condition holds.
Where it goes
On the block to hide. The value is the field to check: its caption as is (Promo text) or the same caption in lower case with dashes (promo-text) — both are one field.
Ready conditions: has_thumbnail (the post has a featured image), login and logout (the visitor is or is not logged in).
Example: a promo banner
<div class="promo" wp-if="promo-text">
<p fld-text="Promo text">Pumpkin latte is back</p>
</div>The promo field is empty, so the banner is not printed at all.
What matters
- A field name works for page fields. For a site setting write the check in full:
wp-if="get_field('phone','options')". - Works on images too:
<img wp-if="has_thumbnail" wp="post-image">.
Common mistakes
The build log is the “Logs” tab of your project on themeforge.pro; the free markup check shows the same notes.
<div class="promo" wp-if="get_field('promo_text'">…</div>An unfinished check (a bracket left open): the build logs the error and hides the block until the condition is fixed.
<div class="promo" wp-if="get_field('promo_text')">…</div>A complete check, or the field’s name.
Alternative spelling
wp_if works the same: the build gives an identical theme.