2

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.

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

2 Answers 2

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';
    }
2
  • 1
    I tried this but it wasn't working for me. What made it work for me is to make the global site language to be Arabic (in settings->general), then going to the specific admin user (in users) and set the preferred language of the user (which is me) to English.
    – Ghadir
    Commented Dec 4, 2021 at 2:16
  • 1
    @Ghadir thanks, you suggestion helped Commented Sep 18, 2023 at 19:26
0

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';
    }

});

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.