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
/*
 * 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 )
   );
 
   if ( $field == 'Yes' || $field == 'yes' ) {
      return $content;
   }
 
   return;
}