Halloween Sale 15% off Ends in See the plans
PHP

Date and Time Formats Per Language

Uses a different date and time format for each language, such as 27 October 2026 in British English and 27. Oktober 2026 in German, whenever the site or user language changes.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_formats = array( // Locale => array( date format, time format ).
    'en_GB' => array( 'j F Y', 'H:i' ),
    'de_DE' => array( 'j. F Y', 'H:i' ),
    'fr_FR' => array( 'j F Y', 'H\hi' ),
    'ja'    => array( 'Y年n月j日', 'H:i' ),
);

add_filter( 'option_date_format', function ( $format ) use ( $wpide_formats ) {
    $locale = determine_locale();

    return isset( $wpide_formats[ $locale ] ) ? $wpide_formats[ $locale ][0] : $format;
} );

add_filter( 'option_time_format', function ( $format ) use ( $wpide_formats ) {
    $locale = determine_locale();

    return isset( $wpide_formats[ $locale ] ) ? $wpide_formats[ $locale ][1] : $format;
} );

Notes

Add locales to $wpide_formats; languages not listed fall back to the formats in Settings > General. Works with any plugin that switches the locale.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.