Open
Overview of the issue
Some themes or plugins use the wp_date() or date_i18n() WordPress functions to display dates. These dates may use a suffix as 1st or 26th, depending on the parameters selected.
Currently, it’s not possible to translate date suffixes because of a longstanding known limitation in WordPress core.
Workaround
As a workaround, you can use the wp_date filter to get the date, then modify the suffix before it’s rendered on the page. Please make a full backup of your site before proceeding and follow the steps below:
- Add the following code to the functions.php file of your theme:
Translate date suffixes in WordPressfunction wpmldp_translate_date_format( $date ) { //Create array with dates $month_dates = array(); $month_dates[] = '1st'; $month_dates[] = '2nd'; $month_dates[] = '3rd'; for($d=4; $d<=30; $d++) { $month_dates[] = $d.'th'; } $month_dates[] = '31st'; //Register strings on String Translator foreach( $month_dates as $month_date ) { do_action( 'wpml_register_single_string', 'Date Formats', 'Month Date (WPML) - '.$month_date, $month_date); } //Translate strings if( in_array($date, $month_dates) ) { $date = apply_filters( 'wpml_translate_single_string', $date, 'Date Formats', 'Month Date (WPML) - '.$date); } return $date; } add_filter( 'wp_date', 'wpmldp_translate_date_format', 10, 1 );
- Open the page where the dates are displayed. This will execute the filter added.
- Go to WPML → String Translation and translate the dates.
- You will need to translate each suffix separately (e.g. 1st, 2nd…) because it may change depending on the language.
I use function get_the_date(D-M-Y) to get the post date, but this is only display english date. How can I translate it in multri language?
Hey there,
Please try to translate the format date in WPML > String Translation. If this does not help, please open a ticket in our support forum so we can help you better.