0

I've a wordpress site with Arabic language, it display the date of post using Gregorian calendar like this 24 فبراير 2016 in hebrew calendar it would be 24 شباط 2016 how can easily do this on any theme ??

  • Skimming through Wikipedia on the definition of the Hebrew calendar, it looks like it's a Lunisolar calendar with 29 or 30 days per Hebrew month, so I guess this calendar change is more than just renaming month strings? – birgire Feb 24 '16 at 9:41
  • actually these names are Arabian names but in the hebrew calendar, I need to change month name "text" only. may re translate these from somewhere on wordpress core help me with this. you can see this reference link .. @birgire – user3003810 Feb 24 '16 at 9:51
1

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 ).' / '.$ar_month.' / '.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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.