WordPress LTR/RTL

Hello,

I found your website on a WordPress forum. Currently I am rebuilding a website in wordpress that is in English and Farsi. I am using the Qtranslate and a theme called suffusion which supports RTL. The theme does come a rtl.css which moves everything to the right which is great. The problem I am having is switching from my LTR Style Sheet to RTL stylesheet when the language is switched. If you could be of any assistance on this it would be greatly appreciated.

Thank You – Chris

First let’s assume that your language is xy_XY (replace with your real language like fr_FR, fa_IR, etc…)

The direction for the language is declared on a php file located on the same directory where your languages files reside, actually the folder /X/wp-content/languages/ (where X is the path to the WP installation).

For each language there should be 3 files:

  • xy_XY.mo [required]: compressed language file, all text strings are pulled from this file
  • xy_XY.po [not required]: Ignore it unless you want to modify the default WP text strings
  • xy_XY.php [not required]: Used for declaring the text direction for the xy_XY language, if not present LTR is assumed

rtl

Don’t be surprised if you don’t find the php file xy_XY.php, your description suggests that it’s missing, so create it and add this line of code:

<?php $text_direction = "rtl"; ?>

This should fix your error and the direction will be set to RTL for your RTL language.

16 comments on “WordPress LTR/RTL

  1. How about if we want to add a conditional statement based on custom field value for example value called switch with key as RTL to switch to RTL for a certain post?

  2. So does this mean I can have both english and arabic posts in my blog and the arabic posts will switch to RTL automatically based on the custom field?

  3. Nabil, I am writing both in English and Urdu (RTL) in my blog. But language folder is missing from my WordPress install. How do I set my language preferences?
    A reply will be highly appreciated.

    Thanks
    Irfan

  4. Thanks a ton Nabeel for a quick reply.
    When I created the folders in my language, and defined the language in config.php; the admin panel also got translated in the language I set.
    Is there a way I can use the admin panel in English while using the language of my choice for posts?

    Thanks.

  5. Hi Nabil,
    Thank you for providing support to us misrepresented rtl folks.
    I am working with farsi and english and sometimes there is a lot
    more that text-direction needed for farsi pages. I made different
    css files for each language. I was wondering about the best way
    to load them up. I have tried loading each css based on current
    language, which is determined by a qtranslate function:
    if(qtrans_getLanguage()==’en’):

    My code is not working but I’m wondering if this is a good practice.
    Is this function being fired off before everything else? If you think
    this should work, this is the code I have in the header so far:

    <?php
    if(qtrans_getLanguage()=='en'): //check the language
    echo 'this is "eng"';
    echo '';
    else if (qtrans_getLanguage()==’fa’):
    echo ‘this is fa mofa!”;
    echo ”;
    ?>

    I tried manual link, or using my themes bloginfo(‘stylesheet_url’) but nothing
    shows to this point.

    I appreciate any suggestion.
    http://www.manArtGallery.com

    • I face the same issue too because I write in Arabic (RTL), what I do while writing a new theme is:
      – I write 3 css file, style.css – for direction neutral css properties like colors, widths, fonts, etc… style-rtl.css and style-ltr.css for direction specific css declarations like padding-right, margin-left, borders, etc, the last two files will have the exact number of line but each property will be defined differently in each file.
      – I make sure that xy_XY.php is present in my XY language directory if the language I use (Arabic in my case) is an RTL language.

  6. Al salam Alaikum Nabil,
    I spent almost half a day searching for this solutions. thanks a million times for this tip. However minor correction the xx_XY.php needs to be save under /wp-includes/languages/ instead of /wp-content/languages folder.

    I wrote the following condition in my themes header file to output the content in the RTL direction:

    <link rel="stylesheet" type="text/css" media="all" href="/rtl.css” />

    I used a nice plugin name RTLer http://wordpress.org/extend/plugins/rtler/ to generate rtl.css for any theme.

    I also used [qTranslate] and [Codestyling Localization] plugins to aid in the translation and localization of themes and other plugins.

    Regards,
    MAD

    • Wa alaikoum assalam

      It’s a bit late to sau that – But never touch the folder wp-includes
      Anyways, I checked again and I confirm that the languages folder resides in wp-content

  7. Hi Nabil

    Thank you for the clear and concise text above.

    However, I followed your steps but still couldn’t get my Arabic site to display rtl.(I am using qtranslate)

    what could be wrong?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>