Can I set is_rtl() to true?

I am adding a section to my site in Pashto, which is a custom Arabic RTL language.

I can figure out how to inject rtl into the html tag and body tag using

add_filter('language_attributes', 'custom_rtl_dir_attr');
add_filter('body_class', 'custom_rtl_body_class');

... but because is_rtl() still returns false, things like the bootstrap rtl css don't get added automatically:

if (is_rtl())
    wp_enqueue_style('bootstrap-rtl', //cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.min.css, array());
}

What I am really looking for is a way to SET is_rtl() to true, for these pages, so that WP treats them like a native RTL page.

Is there any way to set/override is_rtl() ?

Topic language multi-language Wordpress

Category Web


You've got two options:

  1. In wp-config.php, set

    $text_direction = "rtl";
    
  2. If you've defined your own .po or .mo translation file for Pashto (is there really not one already?) there should be a string to translate

    • value: ltr
    • context: text direction

    Set the translation to be "rtl". If that's the user's loaded locale then that will be picked up automatically.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.