Time default value now

This guide will show you how to set the default value of a Time element to be the current time.

Step 1

Go to the Time element settings, Optional tab and tick the option Dynamic default value and enter the Parameter name now

now

Step 2

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

1
2
3
4
5
6
7
8
9
10
11
function my_time_now()
{
    $now = current_time('timestamp');
 
    return array(
        'hour' => date('g', $now),
        'minute' => date('i', $now),
        'ampm' => date('a', $now)
    );
}
add_filter('iphorm_element_value_now', 'my_time_now');
function my_time_now()
{
    $now = current_time('timestamp');

    return array(
        'hour' => date('g', $now),
        'minute' => date('i', $now),
        'ampm' => date('a', $now)
    );
}
add_filter('iphorm_element_value_now', 'my_time_now');

Still having trouble? Head over to the forums.

Forums