The WordPress Multilanguage Plugin, WPML for short is a very popular plugin that allows users to fully operate multilingual websites with WordPress, making it easy to translate WordPress pages, posts, tags, categories, themes and more into multiple languages with minimal overhead.
One thing about the support for this multiple languages support is that we need support for multiple time zones since date/time formatting differs regionally, it makes sense to configure them to be language specific.
The WPML plugin does not do this by out-of-the-box but guess what? here’s a way to change that.
Using the default WordPress installation with no plugin, you set up the date and time formatting under Settings > General.
Since there’s no WPML UI to provide different values per language, we can add a snippet of code that allows you to translate the values using WPML String Translation.
First add the code snippet below to your theme’s functions.php. The code essentially hooks to the optoindate_format
filter.
add_filter( 'option_date_format', function( $format ) { do_action( 'wpml_register_single_string', 'Date formats', 'Date format', $format ); return apply_filters( 'wpml_translate_single_string', $format, 'Date Formats', 'Date format' ); } ); add_filter( 'option_time_format', function( $format ) { do_action( 'wpml_register_single_string', 'Date formats', 'Time format', $format ); return apply_filters( 'wpml_translate_single_string', $format, 'Date Formats', 'Time format' ); } );
After you have added this code in the functions.php. Visit WPML > String Translation and filter by the domain “Date formats”.
This should now return 2 rows for the date and time formats where you can enter the alternative values for the non-default languages. All you need to do after this is to reload the page for the translated dates to appear.
We hope you enjoyed reading this post and found it useful. Feel free to leave your comments in the box below or reach out to our team with all your WordPress website needs. If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.