Change WordPress language in functions.php

742

I want to change the wordpress language in functions.php. WordPress change language

I tried with the below code.

function myprefix_live_site_locale( $locale ) {
    if ( ! is_admin() ) {
        if (strpos($_SERVER['REQUEST_URI'], '/ar/') !== false) {
            return 'ar'; 
        } else {
            return 'tr_TR'; 
        }
    }
    return $locale;
}
add_filter( 'locale', 'myprefix_live_site_locale' );
147

Answer

Solution:

I have checked your script, it looks Okay. There are few changes need to change:

Changestrpos($_SERVER['REQUEST_URI'], '/ar/') tostrpos($_SERVER['REQUEST_URI'], '/ar')

andreturn 'ar' toreturn 'ar_ar'.

function myprefix_live_site_locale( $locale ) {
    if ( ! is_admin() ) {
        if (strpos($_SERVER['REQUEST_URI'], '/ar') !== false) {
            return 'ar_ar'; 
        } else {
            return 'tr_TR'; 
        }
    }
    return $locale;
}
add_filter( 'locale', 'myprefix_live_site_locale' );

People are also looking for solutions to the problem: php - PayPal Sandbox We're sorry, things don't appear to be working at the moment. Please try again later

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.