skip to Main Content

How to Customize Required Field Legend in Gravity Forms

How to Customize Required Field Legend in Gravity Forms

Table of Contents

Here’s your Table of Contents with clickable links:


      Introduction

      Gravity Forms is a powerful WordPress plugin that helps users create custom forms. By default, it displays a generic required field legend, but you can modify it for better user experience.


      Why Customize the Required Field Legend?

      Customizing the legend makes forms clearer for users, ensuring they understand which fields are mandatory. This can improve form completion rates and usability.

      Modify Gravity Forms field legend for WordPress

      Adding Custom Code to Gravity Forms

      You can use a WordPress filter hook to modify the required field legend. The gform_required_legend filter allows you to replace the default text.

      Change required field message in Gravity Forms

      Method 1: Change the Default Required Field Text via Settings

      To customize the required field legend in Gravity Forms without coding, follow these steps:

      1. Navigate to Forms → Settings in your WordPress admin panel.
      2. Locate the Required Field Indicator section.
      3. Modify the text to your preferred message (e.g., “Fields with () are mandatory”*).
      4. Save changes.
      Modify Gravity Forms field legend for WordPress

      Method 2: Customize Using CSS

      You can hide the default legend and add your custom text via CSS:

      .gform_required_legend {
          display: none;
      }
      

      Then, manually add the following custom text above your form in an HTML block:


      Method 3: Modify Using PHP Filter

      Use the following PHP function to modify the required field legend for a specific form (e.g., Form ID 1):

      function custom_gform_required_legend($legend, $form) {
          if ($form['id'] == 1) {
              return 'Required fields are marked with an asterisk (<span class="gfield_required gfield_required_asterisk">*</span>).';
          }
          return $legend;
      }
      add_filter('gform_required_legend', 'custom_gform_required_legend', 10, 2);
      

      Where to Add the Code?

      Add this code to your WordPress theme’s functions.php file or use a custom plugin for better management.


      Testing Your Customization

      After adding the code, check your form to ensure the required field legend displays correctly. If not, clear the cache and test again.


      FAQ

      Can I apply this to all forms?

      Yes! Remove the form ID condition to apply it globally.

      What if the legend doesn’t change?

      Make sure your theme supports Gravity Forms hooks and check for conflicting plugins.

      Can I style the legend differently?

      Yes! Use CSS to customize the appearance of the required field legend.

      I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

      This Post Has 0 Comments

      Leave a Reply

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

      Back To Top