Disclaimer
This is not a complete answer, because I can’t really handle signs I don’t know. It should help to point you in the right direction.
My (basic) solution
Taken from StackExchange, I created this function for your functions.php
:
function ArabicDate( $time = false ) {
if ( $time === false ) {
$time = current_time( 'timestamp' );
}
$months = array("Jan" => "يناير", "Feb" => "فبراير", "Mar" => "مارس", "Apr" => "أبريل", "May" => "مايو", "Jun" => "يونيو", "Jul" => "يوليو", "Aug" => "أغسطس", "Sep" => "سبتمبر", "Oct" => "أكتوبر", "Nov" => "نوفمبر", "Dec" => "ديسمبر");
$your_date = date( 'y-m-d', $time ); // The Date calculated from the $time variable
$en_month = date("M", $time );
foreach ($months as $en => $ar) {
if ($en == $en_month) { $ar_month = $ar; }
}
$find = array ("Sat", "Sun", "Mon", "Tue", "Wed" , "Thu", "Fri");
$replace = array ("السبت", "الأحد", "الإثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة");
$ar_day_format = date('D', $time); // The Current Day
$ar_day = str_replace($find, $replace, $ar_day_format);
$standard = array("0","1","2","3","4","5","6","7","8","9");
$eastern_arabic_symbols = array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩");
// use this line to format your arabic date
$current_date = $ar_day.' '.date( 'd', $time )."https://wordpress.stackexchange.com/".$ar_month."https://wordpress.stackexchange.com/".date( 'Y', $time );
$arabic_date = str_replace($standard , $eastern_arabic_symbols , $current_date);
return $arabic_date;
}
This is not the best solution, as you have to hardcode the timeformat for your arabic date. I would love to do better, but I have no idea how to confirm if the output of the signs is correct.
Change $ar_month
to date( 'm', $time )
if you want the month to be numbers, not the month in text, for example.
Afterwards, you can filter your date function with this code:
add_filter( 'get_the_date', 'f711_convert_to_arabic_date', 10, 3 );
function f711_convert_to_arabic_date( $the_date, $d, $post ) {
$posttime = strtotime( $post->post_date );
return ArabicDate( $posttime );
}
Now your template tags ( get_the_date()
and the_date()
) echo or return your Arabic Date.
If you want to use it in a template, just call echo ArabicDate()
for the current time, or echo ArabicDate( $timestamp )
for any Arabic Date.