Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
  • News
  • Startups
  • Tutorials
  • SEO
  • Marketing
  • Interviews
No Result
View All Result
Dotlayer
No Result
View All Result

How to Add Support for Date/Time Translations Using WPML in WordPress

February 10, 2018
in Tutorials
0 0
Share on FacebookShare on Twitter

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.

ShareTweetPin
Previous Post

How to Use WordPress Shortcodes in a Template in PHP

Next Post

How to Set-up and Install WordPress Using WP-CLI on Ubuntu 16.04 LTS

Next Post

How to Set-up and Install WordPress Using WP-CLI on Ubuntu 16.04 LTS

You might also like

Mint Linux vs Ubuntu: Which is Right For You?

Mint Linux vs Ubuntu: Which is Right For You?

March 12, 2022
Net Neutrality: What is it and Why Should You Care?

Net Neutrality: What is it and Why Should You Care?

March 12, 2022
Solid State Drives – Why You Should Buy One Today

Solid State Drives – Why You Should Buy One Today

March 12, 2022

Machine Learning Algorithms Every Beginner Should Know

January 25, 2022
What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

What Is the log4j Vulnerability, log4shell, an Example Step-By-Step Exploit and How to Fixed It

December 11, 2021
Simple Video Call integration into Website with Jitsi

Simple Video Call integration into Website with Jitsi

May 26, 2020
  • Terms of Service
  • Privacy Policy
  • Careers

© 2021 Dotlayer.com

No Result
View All Result
  • About Us
  • Advertise
  • Blog
  • Careers
  • Contact
  • Contact Us
  • Get Featured
  • Home Layout 1
  • Home Layout 2
  • Home Layout 3
  • Privacy Policy
  • Security
  • Services
  • Subscribe To Dotlayer
  • Terms of Service
  • Write For Us

© 2021 Dotlayer.com

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In