0

I basically need to change the date format to german date format all over the WordPress site and I succeed it by changing the date time settings from the WordPress admin panel.

Settings » General :

Date Format - Custom : j. F Y

eg : 5. July 2016

However I need to change the month names to german as well.

eg : 5. Juli 2016

How should I do that ?

3

go to admin follow 2 simple steps

  1. Date Format - Custom : j. F Y

  2. Change Site Language which one you want change and then save

enter image description here

  • I have tried this solution before, due to some reason the site language is not changing to German. – Janith Chinthana Jul 5 '16 at 17:27
  • @JanithChinthana, you need to ensure the language locale is installed on your server. See askubuntu.com/a/76106/682407 for more info. – Fabian Marz Mar 7 at 9:45
2

I have added the following code to child theme function and it works,

add_filter('the_time', 'modify_date_format');
function modify_date_format(){
    $month_names = array(1=>'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
    return get_the_time('j').'. '.$month_names[get_the_time('n')].' '.get_the_time('Y');
}

But I'm not sure this is the correct way to do it.

  • Great solution if you are not using German as the Wordpress language, many thanks! – nsilva Jan 10 '17 at 14:26
  • this solution is not working for me ? I have added above code in function.php – Narayan Jan 11 '18 at 6:49
2

WordPress has a special function for translating dates, called date_i18n. General usage:

echo date_i18n( $dateformatstring, $unixtimestamp, $gmt);

Supposing you have German as your site's language this would be:

echo date_i18n( 'j. F Y', false, false);

You can also import the time format from the admin settings, like this:

echo date_i18n(get_option('date_format'), false, false);
  • unfortunately I'm not using the german as site's language. – Janith Chinthana Jul 5 '16 at 12:58
  • In that case, you can't use WP's built in translation module. Your own function would be a fine solution then. – cjbj Jul 5 '16 at 13:04
1

Use locale in wp-config.php de_DE, language settings depends on admin panel language, it is possible to separate site language and admin panel language. Also in wp-content>languages look for de_DE.po, use search.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.