-1

Is there any way to switch language in PolyLang plugin like the WPML? For example:

global $sitepress; $sitepress->switch_lang($lang);

1 Answers1

0

Please visit plugin doc for more information regarding polylang plugin functions.

If not possible using Polylang then you can use using default WordPress filter like this :

// Set user selected language by loading the lang.mo file
if ( is_user_logged_in() ) {

    // add local filter
    add_filter('locale', 'language');

    function language($locale) {
        /* Note: user_meta and user_info are two functions made by me,
           user_info will grab the current user ID and use it for
           grabbing user_meta */

        // grab user_meta "lang" value
        $lang = user_meta(user_info('ID', false), 'lang', false); 

        // if user_meta lang is not empty
        if ( !empty($lang) ) {
           $locale = $lang; /* set locale to lang */
        }

        return $locale; 
    }

    // load textdomain and .mo file if "lang" is set
    load_theme_textdomain('theme-domain', TEMPLATEPATH . '/lang');

}
maulik zwt
  • 54
  • 3