I am not sure if I am doing this the right way but I want to avoid using a plugin. I have links on my page to change languages between Spanish and English. I am taking care of everything but when I get the date of the post, it is formatted in the locale of the Wordpress site, for instance:
September 21, 2017
From the Wordpress Codex I found this code to change the locale via a filter.
So I ended up writing this ($language is a global variable that holds the language currently selected by the user):
function set_my_locale( $lang ) {
global $language;
if ( $language == SPANISH_LOCALE) {
// set to Spanish
return 'es_ES';
}
else if ( $language == ENGLISH_LOCALE) {
// set to English
return 'en_US';
}
}
add_filter('locale','set_my_locale');
The function gets called and nothing is changed, the date is still shown in English.
Oh, I do have es_ES.mo and es_ES.po files inside the languages folder and I can switch to Spanish in the admin interface, so they are correctly installed.
I have run out of ideas, any clues why the dates are displayed in English regardless of what I do?