I previously was able to change the numbers of the date and time (into a number and date system of another language, like Khmer) for each post using a script like this in my functions.php:
function KhmerNumDate ($text) {
$text = str_replace('1', 'á¡', $text);
$text = str_replace('2', 'á¢', $text);
$text = str_replace('3', 'á£', $text);
$text = str_replace('4', 'á¤', $text);
$text = str_replace('5', 'á¥', $text);
$text = str_replace('6', 'á¦', $text);
$text = str_replace('7', 'á§', $text);
$text = str_replace('8', 'á¨', $text);
$text = str_replace('9', 'á©', $text);
$text = str_replace('0', 'á ', $text);
return $text;
}
add_filter('date', 'KhmerNumDate');
add_filter('the_date', 'KhmerNumDate');
add_filter('the_time', 'KhmerNumDate');
But now it is not working – is my code good? Would the code differ based on which theme I am using (I am currently using a modified child theme of Twenty-Twelve)?
Please try this way:
Change date, the_date, the_time to get_date, get_the_date, get_the_time.
Turns out it was because of the way the theme Twenty Twelve works (in their effort to make translation easy…).
The date for posts in Twenty Twelve is prepared by a function in functions.php called
twentytwelve_entry_meta()
So to replace/translate the numbers in the date, I look for the line with
$date=
in thetwentytwelve_entry_meta()
function (or preferably replicate thetwentytwelve_entry_meta()
function in a child functions.php as I did):Then everything looks great!
I’m not much of a programmer, so my code might not be the best option, but at least it works.
I would like suggest using a WordPress built-in function for your specific need which is
date_i18n($date_format, $time, $gmt)
. Just pass the phpdate()
format and thetimestamp
and WordPress will display the date in your language (Language defined inwp-config.php
).Example from the codex page: