Home / Archive / WPForms: new smart tag – Current Date/Time
Duplicate Snippet

Embed Snippet on Your Site

WPForms: new smart tag – Current Date/Time

It's a localized date/time in this format: Y-m-d H:i:s

Code Preview
php
<?php
// Register the smart tag.
add_filter( 'wpforms_smart_tags', static function( $tags ) {
	// Key is the tag, value is the tag name.
	$tags['current_time'] = 'Current Date/Time';
	return $tags;
} );
// Replace its value on form render on front-end.
add_filter( 'wpforms_process_smart_tags', static function( $field_val, $form_data ) {
	return str_replace( '{current_time}', date_i18n( 'Y-m-d H:i:s' ), $field_val );
}, 10, 2 );

Comments

Add a Comment