Is there anyway to get wordpress to automatically switch locales based on the HTTP Accept-Language header?

Similar to how ASP.NET can do it with their globalization="auto" config setting. The reason for this is that I want my dates to be custom formatted based on where you are viewing the site from - not what the wordpress site settings use for everybody around the world.

This way somebody from the USA (en-US) will see 12/25/2011 but somebody from Australia (en-AU) will see 25/12/2011.


that's going to be a bit tricky since WordPress doesn't relate date and time format to language. so to get the current language from the browser you can use $_SERVER['HTTP_ACCEPT_LANGUAGE'] and then based on that you can change the date format:

function update_date_format(){
    if (strpos($lang, 'au') > 0){
        $date_format = 'd/m/Y'; // 25/12/2011
        $date_format = 'm/d/Y'; // 12/25/2011

after you paste this function in your theme's functions.php add to your theme's header.php at the very top:

<?php update_date_format(); ?>

Your Answer

