How to remove "*required field" notice and where to put the code? [RESOLVED]

Hello,

As will be obvious from my post, I don’t know much about coding. I am trying to get rid of the " *required field" notice at the top of my form. I searched the community, and found this thread, which has a solution.

But for the life of me, I cannot work out where this code needs to go. I am using a Divi Child theme. I also have a gravity forms styler plugin uploaded.

The code I’m using is:

add_filter( 'gform_required_legend', function( $legend, $form ) {
    return '* indicates required fields';
}, 10, 2 );

I have also tried this:

add_filter( 'gform_required_legend', '__return_empty_string' );

I have tried pasting the code in these places (in turn, obviously, not all at the same time):

-The CSS section in the general settings of the Form Styler plugin
-The “Additional CSS” box at the bottom of the WP customiser options
-The Divi Theme Editor

None of it makes any difference. The message stays. I’m out of ideas… please could someone advise? Many thanks.

It sounds like you’re on the right track with using a filter to remove the required field notice. The code you’re using is correct, but you must add it to your theme or child theme’s functions.php file.

It is best to create a child theme to ensure your changes are not lost when the theme is updated. Here are the steps to add the code to your functions.php file:

  1. Log in to your WordPress dashboard and go to Appearance > Theme Editor.

  2. In the Theme Editor, find the functions.php file in the list of theme files on the right-hand side.

  3. If it exists, open the functions.php file and paste the code at the bottom, just before the closing PHP tag (?>).

  4. Save the functions.php file.

This should remove the required field notice from your form. If it doesn’t work, ensure the code is correctly formatted and there are no syntax errors.

By creating a child theme, you can customize your site without worrying about losing them when you update the theme.

If you’re facing difficulties creating a child theme, try the Code Snippets plugin to add the PHP code without a child theme. Here is a guideline for you: Wordpress Code Snippets Tutorial | Add Custom PHP and CSS To Your Website - YouTube

Thank you very much! I’m using a child theme in any case and I can find the functions file via ftp. I just didn’t know where to put it. Thanks so much, I’ll report back if it did the job.

Sure, take your time, and let me know how it goes! Here’s an example to help you insert your code into the functions.php file. :smiley:

<?php
// code
// code
// code
// and
// lots of codes

// your new code
add_filter( 'gform_required_legend', function( $legend, $form ) {
    return '* indicates required fields';
}, 10, 2 );

// ---- OR ----
add_filter( 'gform_required_legend', '__return_empty_string' );

// make sure to put it before the end of the line
?>

Amazing, thank you! The second, shorter code did the job.

There was no ?> anywhere at the end of the code, but I don’t care, it’s working! :slight_smile:

1 Like

It’s great to hear that the issue has been resolved! PHP closing tags are not required, so you won’t find them in every PHP file.

Congratulations on a job well done! Wishing you the best of luck in the future. @yblume :wink:

1 Like

Thanks! :smiling_face:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.