Change date number to another language/script?

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)?

3 Answers
3

Please try this way:

Change date, the_date, the_time to get_date, get_the_date, get_the_time.

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('get_date', 'KhmerNumDate');
add_filter('get_the_date', 'KhmerNumDate');
add_filter('get_the_time', 'KhmerNumDate');

Leave a Comment