How to load rtl.css file without changing language to Persian in WordPress?

admin2025-01-07  3

I have a rtl.css file for my theme. When I change the site language to Persian (from settings), rtl.css is loaded and works properly. But I want to keep it in English language and load rtl.css file. How I do it? When the language changes, what happens?

I have a rtl.css file for my theme. When I change the site language to Persian (from settings), rtl.css is loaded and works properly. But I want to keep it in English language and load rtl.css file. How I do it? When the language changes, what happens?

Share Improve this question edited Dec 30, 2024 at 19:50 Glorfindel 6093 gold badges10 silver badges18 bronze badges asked Jan 17, 2017 at 10:25 Saeid MSaeid M 12 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0
# if you want to enqueue your style in you theme, rtl or else

function theme_enqueue_scripts() {

    # enqueue style in your theme

    wp_register_style( 'rtl', get_template_directory_uri() . '/css/rtl.css', array(), '1.0.0' );
    wp_enqueue_style( 'rtl' );


}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );

# if you need enqueue this, just if theme is rtl , copy this function

function theme_enqueue_scripts() {

    if ( is_rtl() ) {

        wp_register_style( 'rtl', get_template_directory_uri() . '/css/rtl.css', array(), '1.0.0' );
        wp_enqueue_style( 'rtl' );

    }


}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_scripts' );

When you change the language, WordPress automatically loads the rtl.css. How that happens is explained here.

As to use rtl.css without switching to a rtl language, have you read the Codex page? There are automated tools that can help you flip your website.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254639a222.html

最新回复(0)