Categories
WordPress

Enable Shortcodes for Gravity Forms Field Descriptions

To enable shortcodes inside your Gravity Forms form description, field labels and descriptions, you need to add the following code to your theme’s functions.php file:

// Updated in January 2021
add_filter( 'gform_pre_render', 'walker_do_shortcode_gform_description', 10, 2 );

function do_shortcode_gform_description( &$item, $key ) {
	
	// Back-compatibility for a VERY old version of GF
	if ( is_string( $item ) ) {
		$item = do_shortcode( $item );
	} else {
		$item['description'] = do_shortcode( $item['description'] );
	}
}

function walker_do_shortcode_gform_description( $form, $ajax ) {

	$form['description'] = do_shortcode( $form['description'] );
	array_walk_recursive( $form['fields'], 'do_shortcode_gform_description' );

	return $form;
}

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

4 replies on “Enable Shortcodes for Gravity Forms Field Descriptions”

I’d hoped this was just what I was looking for, do you happen to know if this code is still valid? If not, could you advise how it needs updating?

Works for me as of today on Gravity Forms 1.9.13 on WordPress 4.3.1. Only thing that needs changing is the smart quotes in the code. Just change the ‘ and ’ to ‘ the straight single quote.

No worries, I had a quick look and then figured as I pay for GF support I’d ask them.
Turns out their is a proper hook etc to do just this in a lot less code as follows:

add_filter( ‘gform_get_form_filter’, ‘shortcode_unautop’, 11 );
add_filter( ‘gform_get_form_filter’, ‘do_shortcode’, 11 );

This will allow shortcodes to work in any field across the whole form.

Comments are closed.