Create additional custom pre-defined merge tags - Code Parrots

Knowledge Base

Create additional custom pre-defined merge tags

Article Last Updated: March 4, 2021

Out of the box we provide some basic pre-defined merge tags for you to populate your Mailchimp form fields with. These merge tags can be extremely beneficial for analytic purposes, separating users into groups, figuring out where users are signing up for and much more. But often these fields aren’t enough to achieve what you are after.

Thinking of our users, we’ve built in quite an easy method for users to define their own pre-defined merge tags for use in the Mailchimp form fields. With just a little bit of code, users can add additional tags to the pre-defined merge tag list, and populate fields with whatever data they see fit.

; '{YIKES_Example}', // tag that will be parsed
        'description' =>; 'Yikes New | {YIKES_Example}' . __( 'This is the description that appears in the tooltip, when hovering on the question mark icon.' , 'yikes-inc-easy-mailchimp-extender' ), /// tool tip content that appears on hover
        'title' =>; 'YIKES Example' // title of the link (on hover, used for accessibility purposes)
    );
return $available_tags; // return the new tags
}

?>

The above snippet, add_new_pre_defined_tags, is hooked into yikes-mailchimp-custom-default-value-tags, which is used to display the merge tags back to you in the admin dashboard. Copying and pasting the above snippet into your functions.php file will now display a new merge tag titled ‘{YIKES_Example}’ under the ‘Pre Defined tags’ section.

The final bit of code that you need to implement, is a small snippet which tells WordPress how to process the tag, and what value to return to the input field.

user_firstname; // {YIKES_Example} parsed into the currently logged in users first name
        }
    }
// return the newly parsed data back to the input field
return $tag;
}

?>

In the above example we’re parsing the {YIKES_Example} tag, and returning the currently logged in users first name (if it is set, else it will be a blank field).

As you can see from the above two snippets, extending Easy Forms for Mailchimp by YIKES and building out additional, custom, pre-defined tags to populate your Mailchimp forms with is quick and simple. We’ve provided a very flexible system for any number of uses.