Change the date format on a certificate

Note: This is a Developer level doc. If you are unfamiliar with code/templates, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our Support Policy.

From v1.0.5 of certificates, if you use {{completion date}} in your certificate template, it will automatically use the correct language for the month name, based on the language you set in your wp-config.php file

However, depending on your language, you may want to rearrange the date format to display the elements in a different order.

By default the date is formatted as follows:

English:

jS F Y

This outputs as e.g. 27th May 2014

Non-English:

%Y %B %e

This outputs as e.g. 2014 Mai 27 (using German as an example).

To change the format, you’ll need to add some code to your theme’s functions.php file, and then edit the format code depending on the language you’re using.

For English sites, you can use any of the date format codes provided here – http://php.net/manual/en/function.date.php

e.g. Add the following to your functions.php file:

add_filter( 'sensei_certificate_date_format', 'sensei_reorder_certificate_date' );

function sensei_reorder_certificate_date() {
$date_format = 'Y F j';
return $date_format;
}

This would change the date to e.g. 2014 May 27

For non-English sites, you need to use the date format codes provided here – http://www.php.net/manual/en/function.strftime.php

e.g. Add the following to your functions.php file:

add_filter( 'sensei_certificate_date_format', 'sensei_reorder_certificate_date' );

function sensei_reorder_certificate_date() {
$date_format = '%e %B %Y';
return $date_format;
}

This would change the date to e.g. 27 Mai 2014

If you try to use English date codes on a non-English site, or vice-versa, it won’t work properly.

2 thoughts on “Change the date format on a certificate

Leave a Reply

Your email address will not be published. Required fields are marked *