Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
2  
Have a look at this, wordpress.stackexchange.com/questions/21752/… –  Wyck Jan 30 '13 at 4:42
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.