0
Days
0
Hours
0
Minutes
0
Seconds

Black Friday Sale - Get 30% OFF. Grab our only sale of the year!

Use discount code BF2024 at checkout.

A Cozmoslabs Product
Documentation / Developer Knowledge Base / Shortcodes / Yes or No conditional shortcode

Yes or No conditional shortcode

This function adds a Yes or No conditional shortcode.

Shortcode:

[yes_no_display field=”{custom_field_3}”]
This is displayed only if field = Yes
[/yes_no_display]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * Yes No shortcode. Tags: contitional, shortcode, yes, no
 * Use like so: [yes_no_display field="{custom_field_3}"]This is displayed only if field = Yes.[/yes_no_display]
 */
 
add_shortcode( 'yes_no_display', 'wppbc_is_field_yes_or_no' );
function wppbc_is_field_yes_or_no( $atts, $content ) {
   extract(
      shortcode_atts( array( 'field' => '' ), $atts )
   );
 
    $user_id = get_current_user_id();
    $meta_key = trim( $atts['field'],"{}");
    $field = get_user_meta( $user_id, $meta_key, true );
 
   if ( $field == 'Yes' || $field == 'yes' ) {
      return $content;
   }
 
   return;
}

Profile Builder Pro

Create beautiful front-end registration and profile forms with custom fields. Setup member directories, custom redirects, cutomize user emails & more using the all in one user management plugin.

Get Profile Builder

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket