Skip to content
themeforge
EN
Start free
Menu
  1. Home
  2. Attribute reference
  3. wp-if
Core Show on a condition

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

Markup menu.html
<div class="promo" wp-if="promo-text">
  <p fld-text="Promo text">Pumpkin latte is back</p>
</div>
In the admin Pages → Menu
Promo text
On the site the field is empty
Menu
Latte $4.20
Cappuccino $3.90

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.

Not like this
<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.

Like this
<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.

Ready when you are

See your site’s WordPress admin before you pay.