Skip to main content

$form = GFAPI::get_form( $atts['form_id'] ); if ( ! $form ) return '';

return $condition_met ? do_shortcode( $content ) : ''; [gf_conditional form_id="1" field_id="3" value="Option A"] You selected Option A! [/gf_conditional] 🧠 Real-World Examples Example 1: Show a special message after submission [gf_conditional form_id="5" field_id="2" value="Business"] Thanks! A business account manager will contact you. [/gf_conditional] Example 2: Show different content for different selections [gf_conditional form_id="5" field_id="4" value="Yes" operator="="] ✅ Great! We'll send you the guide. [/gf_conditional] [gf_conditional form_id="5" field_id="4" value="No" operator="="] ❌ No problem. You can still browse our resources. [/gf_conditional] 🔁 Alternative: Gravity Forms Merge Tags + Conditional Shortcode You can combine merge tags with conditional logic:

add_shortcode( 'gf_conditional', 'gf_conditional_shortcode' ); function gf_conditional_shortcode( $atts, $content = null ) ! $atts['field_id'] ) return '';

// Get submitted field value (works after form submission) $field_value = rgpost( "input_$atts['field_id']" );

// Compare using operator $condition_met = false; switch ( $atts['operator'] ) case '=': $condition_met = ( $field_value == $atts['value'] ); break; case '!=': $condition_met = ( $field_value != $atts['value'] ); break; case 'contains': $condition_met = ( strpos( $field_value, $atts['value'] ) !== false ); break;

[gravityforms_conditional form_id="1" field_id="2" value="Yes"] This content shows only if field 2 = Yes. [/gravityforms_conditional] Some plugins support multiple operators: = , != , > , < , contains , etc. Add this to your theme’s functions.php file:

gravity forms conditional shortcode

If you continue to use this site, you consent to use all cookies. We use cookies to offer you a better browsing experience. Read how we use cookies and how you can control them by visiting our Privacy Policy.

If you continue to use this site, you consent to use all cookies.