0

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.

1

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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