We have an English WP website and now use GTranslate to support Arabic language as well.
The English site is https://www.example.com/ The Arabic version is https://www.example.com/ar/ (Note /ar/ is a virtual directory created by .htaccess redirection)
Now after studying the WordPress document at https://codex.wordpress.org/Right-to-Left_Language_Support#Method_2:_rtl.css. It said to create a rtl.css but does not say how to use it.
Based on other document such as https://torquemag.io/2018/03/rtl-support-wordpress/, it seems WP will automatically load rtl.css if I put the file under the same directory as style.css and the language is rtl.
However, based on my test, it is not the case. I put the rtl.css at the same directory as style.css, then go do Arabic version https://www.example.com/ar/ but in Chrome DevTools, rtl.css is not loaded.
So, I just wonder how WP determine whether it should load rtl.css, based on the tag or something else?
WordPress uses the function
is_rtl()to decide whether it should load thertl.cssfile or not. What this function does based on WordPress is:Since the main language for the website is English, it will always return
falsewhich will result in thertl.cssnot being loaded.So, there are 2 ways to load this files. Either by setting the global variable
$text_directionbeforeWP_Localeclass is initialized when the URL has /ar. Or by enqueuing thertl.cssfiles based a similar URL condition.This is an example snippet to enqueue styles conditionally based on the current URL: