Skip to content Skip to sidebar

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 WordPress
    function 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 WPMLString 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.

2 Responses to “Not possible to translate date suffixes in WordPress”

    • 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.

Leave a Reply

Please stay on topic and be respectful to others. If you need help with issues not related to this post, use our Support Forum to start a chat or submit a ticket.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>