Skip to content

Instantly share code, notes, and snippets.

@yuliyang
Created December 20, 2021 11:40
Show Gist options
  • Save yuliyang/ac8d4e1f3af3575a68b4cbba6e1b2d06 to your computer and use it in GitHub Desktop.
Save yuliyang/ac8d4e1f3af3575a68b4cbba6e1b2d06 to your computer and use it in GitHub Desktop.
[Gravity Forms] Custom Merge Tags
<?php
add_filter('gform_custom_merge_tags', 'ching_custom_merge_tags', 10, 4);
function ching_custom_merge_tags( $merge_tags, $form_id, $fields, $element_id ) {
$merge_tags[] = array('label' => 'Open Present', 'tag' => '{open_present}');
return $merge_tags;
}
add_filter('gform_replace_merge_tags', 'ching_replace_merge_tags', 10, 3);
function ching_replace_merge_tags( $text, $form, $entry ) {
if ( strpos( $text, '{open_present}' ) ) {
$text = str_replace( '{open_present}', 'Here it is!', $text );
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment