Skip to content

Instantly share code, notes, and snippets.

@pramodjodhani
Created February 6, 2024 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pramodjodhani/656848aaed62e0e633638805f4115534 to your computer and use it in GitHub Desktop.
Save pramodjodhani/656848aaed62e0e633638805f4115534 to your computer and use it in GitHub Desktop.
Add a custom merge tag {custom_today_ymd}
<?php
// Create a custom merge tag for gravity forms.
add_filter( 'gform_custom_merge_tags', 'pj_add_custom_merge_tags', 10, 4 );
function pj_add_custom_merge_tags( $merge_tags, $form_id, $fields, $element_id ) {
$merge_tags[] = array( 'label' => 'Today date(Y-M-D)', 'tag' => '{custom_today_ymd}' );
return $merge_tags;
}
// Add a custom merge tag to the list of available merge tags in the form editor.
add_filter( 'gform_merge_tags', 'pj_add_custom_merge_tag', 10, 4 );
function pj_add_custom_merge_tag( $merge_tags, $form_id, $fields, $element_id ) {
$merge_tags['today_date_ymd'] = '{custom_today_ymd}';
return $merge_tags;
}
// Replace the custom merge tag with the value you want.
add_filter( 'gform_replace_merge_tags', 'pj_replace_custom_merge_tag', 10, 7 );
function pj_replace_custom_merge_tag( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {
$text = str_replace( '{custom_today_ymd}', wp_date( 'Y-m-d' ), $text );
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment