How to change frontend language according to wordpress admin dashboard?

Question

I want to change the front page language according to wordpress admin language.

When i will change the wordpress admin language, then frontpage should also translate into that language.

I don’t want to use any plugin, just trying to use wordpress inbuild method or function.

Currently i am trying this code.

// Getting blog language
$lang=get_bloginfo("language");

$lng=str_replace('-', '_', $lang);

//Now output will be en_US
echo $lng;

function wp_noshor_redefine_locale($locale) {
    if(is_admin()){
        switch_to_locale("$lng");
    }

    if ( is_front_page() ) { 
        switch_to_locale("$lng");
    } 
}
add_filter('init','wp_noshor_redefine_locale');

Ps: word press admin dashboard language changing successfully, but homepage does not have any change.

0
, , , ajay kumar 3 years 2019-10-22T00:08:58-05:00 0 Answers 98 views 0

Leave an answer

Browse
Browse