Format Date shortcode

This shortcode can be used to display a date captured with the Datepicker field, inside the Userlisting, in a different format than the one it was saved it.

Shortcode:
[wppb-format-date date=”{{meta_datepicker}}” format=”d/m/y”]

This makes use of PHPs date() function. Consult the documentation page in order to figure out how to change the format to the one you want.

You can add this shortcode to your website using the Customization Toolbox add-on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 *  Will format a date using the PHP date() function. 
 *  Usage: [wppb-format-date date="{{meta_datepicker}}" format="d/m/y"]
 */
add_shortcode( 'wppb-format-date', 'wppbc_format_date_handler' );
function wppbc_format_date_handler( $atts ){
	$a = shortcode_atts( array(
		   'date' => null,
		   'format' => null,
	),$atts );
 
	if ($a['date'] === null)
		return;
 
	if ($a['format'] === null)
		return $a['date'];
 
	$date = strtotime($a['date']);
 
	return date($a['format'], $date);
}