Change the date format on a certificate

Posted on April 25, 2017 by Dan Johnson

A Sensei Bizonyítványok (Sensei Certificates) 1.0.5-s verziójától kezdve, ha használod a {{completion date}} shortkódot a bizonyítvány sablonodban, akkor az automatikusan a wp-config.php fájlodban beállított nyelv szerinti hónap nevet fogja használni.

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.