Skip to content

Format dates with WPML

Maylis Agniel edited this page Aug 15, 2018 · 1 revision

Automatically format date attribute based on the given date format in WPML > String translation

functions.php

function translate_date_format($format) {
    if (function_exists('icl_translate'))
      $format = icl_translate('Formats', 'Y/m/d', 'Y/m/d');
    
    return $format;
}
add_filter('option_date_format', 'translate_date_format');

Usage in Twig templates

{{__('Published on %s')|format(date) }}
Clone this wiki locally