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.

5 Comments

  1. chris says:

    Thank you so much! This worked

  2. Al says:

    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?

    • Nabil says:

      You can add this to the beginning of your index.php file or in the functions.php if you have one.

      <?php
       
        $custom_fields = get_post_custom(/* Current Post */);
        if($custom_fields['switch'] === 'RTL'){
          $text_direction = "rtl";    
        }
       
      ?>
  3. Al says:

    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?

Leave a Reply