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:


add_filter(‘gform_pre_render’, ‘walker_do_shortcode_gform_description’, 10, 2);

function do_shortcode_gform_description(&$item, $key) {
$item = do_shortcode($item);
}

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;
}

Author: Zack Katz

Zack Katz is the President of Katz Web Services and the developer of WordPress plugins with over 700,000 downloads. He lives in Southwest Colorado with his wife and two cats.

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

  1. 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?

    1. 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.

      1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *