Using Gravity Forms ‘gform_merge_tag_data’ PHP action

The gform_merge_tag_data filter in Gravity Forms allows you to add, modify, or remove data that will be used to replace merge tags in a specified string. This filter is intended for implementing custom merge tags used in notifications, confirmations, and feed add-ons. It is not triggered during form display.


To apply this filter to all forms:

add_filter('gform_merge_tag_data', 'your_function_name', 10, 4);


  • $data (array): Data used to replace merge tags. Array keys represent available merge tags. Values can be accessed by specifying a property: {entry:date_created}. Value can be an array of data or a callable function.
  • $text (string): The current text that will be parsed for merge tags.
  • $form (Form Object): The current form object.
  • $entry (Entry Object): The current entry object.

More information

See Gravity Forms Docs: gform_merge_tag_data


Provide Custom Data

This example adds custom data to merge tags:

add_filter('gform_merge_tag_data', 'my_custom_merge_tag_data', 10, 4);

function my_custom_merge_tag_data($data, $text, $form, $entry) {
    $data['myCustomTag'] = array(
        'key1' => 'Value One',
        'key2' => 'Value Two'
    return $data;

Entry Creator

This example adds a {created_by} merge tag to return a comma-separated string containing the roles assigned to the user who created the entry:

add_filter('gform_merge_tag_data', function ($data, $text, $form, $entry) {
    $data['created_by'] = array();
    if (!empty($entry['created_by'])) {
        $user = new WP_User($entry['created_by']);
        $data['created_by'] = get_object_vars($user->data);
        $data['created_by']['first_name'] = $user->get('first_name');
        $data['created_by']['last_name'] = $user->get('last_name');
        $data['created_by']['roles'] = implode(', ', $user->roles);
    return $data;
}, 10, 4);


  • Added the $entry parameter.
  • 2.0: Introduced.

Source Code

This filter is located in GFCommon::replace_variables() in common.php.