Using Gravity Forms ‘gform_custom_merge_tags’ PHP filter

The gform_custom_merge_tags Gravity Forms filter allows for the inclusion of custom merge tags wherever merge tag drop downs are generated.

Usage

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

Parameters

  • $merge_tags (array): The merge tags.
  • $form_id (int): The ID of the current form.
  • $fields (Field Object): A collection of field objects.
  • $element_id (int): The ID of the input field.

More information

See Gravity Forms Docs: gform_custom_merge_tags

Examples

This example adds a custom merge tag for a download link:

add_filter('gform_custom_merge_tags', 'custom_merge_tags', 10, 4);

function custom_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'Download Link', 'tag' => '{download_link}');
    return $merge_tags;
}

Adding a custom name merge tag

This example adds a custom merge tag for a full name:

add_filter('gform_custom_merge_tags', 'custom_name_merge_tags', 10, 4);

function custom_name_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'Full Name', 'tag' => '{full_name}');
    return $merge_tags;
}

Adding a custom event date merge tag

This example adds a custom merge tag for an event date:

add_filter('gform_custom_merge_tags', 'custom_event_date_merge_tags', 10, 4);

function custom_event_date_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'Event Date', 'tag' => '{event_date}');
    return $merge_tags;
}

Adding a custom order number merge tag

This example adds a custom merge tag for an order number:

add_filter('gform_custom_merge_tags', 'custom_order_number_merge_tags', 10, 4);

function custom_order_number_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'Order Number', 'tag' => '{order_number}');
    return $merge_tags;
}

Adding a custom discount code merge tag

This example adds a custom merge tag for a discount code:

add_filter('gform_custom_merge_tags', 'custom_discount_code_merge_tags', 10, 4);

function custom_discount_code_merge_tags($merge_tags, $form_id, $fields, $element_id) {
    $merge_tags[] = array('label' => 'Discount Code', 'tag' => '{discount_code}');
    return $merge_tags;
}