Last active
May 23, 2017 17:37
-
-
Save robinbastien/f5384dcbc77498b6d2fb to your computer and use it in GitHub Desktop.
WPML - Multilingual Date Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Friendly Date (WPML) | |
* Adds a date in the proper language based on a timestamp | |
* @param timestamp $timestamp A unix timestamp | |
* @param language $language The locale code. In most cases this will be ICL_LANGUAGE_CODE | |
* @param short $short The date format to output (eg: 'l F jS, Y') | |
*/ | |
function friendly_date_wpml($timestamp, $language, $short) { | |
$format = ($short) ? 'F jS' : 'l F jS, Y'; | |
$date = date($format, $timestamp ); | |
// if french, show french date | |
if( $language == 'fr' ) { | |
setlocale(LC_TIME, "fr_FR"); | |
$format = ($short) ? "%e %B" : "%A le %e %B, %Y"; | |
$date = strftime($format, $timestamp); | |
$date = htmlentities($date, ENT_COMPAT, 'ISO-8859-1'); | |
} | |
return $date; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment