Apply an asterisk to specified Mailchimp form fields

Article Last Updated: July 8, 2019

When we transitioned from v5 to v6 we removed the asterisk from the front end display of all Mailchimp forms. We did this due to the overwhelming number of users who wanted them removed. So instead of constantly providing users with code to remove the asterisk fields, we decided it would be best to remove them out of the box and provide those who still want them with a solution.

The first thing you need to do is decide which of your fields you’d like to have an asterisk assigned too. For each of these fields you’ll need to know the Merge Tag value. You can find the merge tag value by expanding the specific field on the ‘edit form’ page.

The next step is to add the following snippet the bottom of your active themes function.php file. You’ll want to populate the $required_field_merge_tags p array with the merge tags of your fields. You’ll see in the code snippet below that I am assigning an asterisk to the Email field and the First Name fields by passing in the ‘EMAIL’ and ‘FNAME’ merge tags.

/*
*	Apply an asterisk to indicate this field is required
*	@demonstration
*/

function yikes_mailchimp_add_asterisks_to_fields( $label_text ) {
    return $label_text . ' <span style="color:#F96969;">*</span>';
}

/* Build an array of fields to set as required */
$required_field_merge_tags = array(
    'EMAIL',
    'FNAME'
);

/*
*	Loop over the fields above
*	and append an asterisk to indicate the field is required
*/

foreach( $required_field_merge_tags as $merge_tag ) {
    add_action( 'yikes-mailchimp-' . $merge_tag . '-label', 'yikes_mailchimp_add_asterisks_to_fields' );
}

?>

After the code snippet is added to your functions.php file, you’ll want to save out the file and check to ensure that the asterisks are displaying properly on the front end.

Notes: To change the color of the asterisk simply adjust the hex value in the code.
<span style="color:#F96969;">*</span>