Modify Date Format to German

All we need is an easy explanation of the problem, so here it is.

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 ?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

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);

Method 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.

Method 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

Method 4

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.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply