admin管理员组

文章数量:1122846

I'm working on a website that needs to be RTL, after reading some articles online I understood that in order for the website to be RTL I need to change the site language to a RTL language.

Through this path: Settings >> General >> Site Language

Did that and it changed the website to RTL but it changed all the website's content (front-end and admin panel) to the RTL language.

Can I change only the front-end part to RTL without changing my admin panel's language?

Thanks.

I'm working on a website that needs to be RTL, after reading some articles online I understood that in order for the website to be RTL I need to change the site language to a RTL language.

Through this path: Settings >> General >> Site Language

Did that and it changed the website to RTL but it changed all the website's content (front-end and admin panel) to the RTL language.

Can I change only the front-end part to RTL without changing my admin panel's language?

Thanks.

Share Improve this question asked Feb 7, 2018 at 18:53 TonyTony 211 silver badge2 bronze badges 3
  • tu use differents languages in frontend and backend, you can use a plugin like Polylang : wordpress.org/plugins/polylang – mmm Commented Feb 7, 2018 at 18:57
  • check this, here exactly answered wptavern.com/… – Abdul Aziz Commented Dec 21, 2019 at 7:34
  • I had this exact problem and almost went for a multilingual plugin just to solve it. What eventually solved it for me is to set the global site language to be Arabic (settings -> general), and then going to my user (in users) and setting my preferred language to English. – Ghadir Commented Dec 4, 2021 at 2:18
Add a comment  | 

2 Answers 2

Reset to default 0

Set your WordPress to a RTL language, then use the following code in functions.php or as the plugin:

<?php
add_filter( 'locale', 'my_set_admin_locale' );

function my_set_admin_locale( $locale ) {

    // check if you are in the Admin area
    if( is_admin() ) {
        // set LTR locale
        $locale = 'en_US';
    }

    return( $locale );
}

Or otherwise, set WordPress to LTR and set front-end to RTL:

    if( ! is_admin() ) { // not admin area
        // set RTL locale
        $locale = 'ar';
    }

Like so :

add_filter('locale', function ($locale) {

    global $wp_locale;

    if (isset($_COOKIE['farsi'])) {
        $wp_locale->text_direction = 'rtl';
        return 'fa_IR';

    } else {
        $wp_locale->text_direction = 'ltr';
        return 'en_US';
    }

});

本文标签: How to make the frontend RTL without changing the admin panel language