WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on adding a language variable (locale) in my custom WordPress theme. I made the translation working by adding ?l=en_US to the URL. I would like to add the parameter into COOKIE, such that the site will remember the choice.

Also, I would like to build a language switcher ( allow visitors to choose their own language ). How should I achieve it ?

I am able to get the locale by (and load the text domain):

add_action('after_setup_theme', 'DYtheme_setup');
add_filter('locale', 'DYtheme_localized');
function DYtheme_setup(){
    load_theme_textdomain('donnie2012', get_template_directory() . '/lang');
function DYtheme_localized($locale) {
    if (isset($_GET['l'])) {
        return $_GET['l'];
    return $locale;

but how to make the language parameter into COOKIE & also in URL ? I've looked into add_query_args but I'm not sure I'm in right track.

share|improve this question
Have a look at this, wordpress.stackexchange.com/questions/21752/… – Wyck Jan 30 '13 at 4:42

With honor to @Wyck's link, I managed to add a language variable by adding an action hook to init and set the locale into cookie using PHP's setcookie() function.

For details, visit: Setting custom cookies in Wordpress

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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