3

Sorry if this is an ignorant question. I'm a first timer on working with rtl languages. Say we have a theme with standard style.css for English languages. so I use is_rtl() and this returns TRUE, we won't load the style.css and only rtl.css?

IF someone can provide an example on this on loading rtl.css on rtl languages and style.css on other languages (aside from the WordPress documentation which I already seen), I would be happy. Thanks.

8

In your theme, you enqueue the stylesheet usually like this:

add_action( 'wp_enqueue_scripts',   't5_enqueue_style' );

function t5_enqueue_style()
{
    wp_enqueue_style(
        'theme-name-default',
        get_template_directory_uri() . '/css/default.min.css'
    );
}

The extra RTL stylesheet is enqueued here too, listing the default as dependency:

if ( is_rtl() )
{
    wp_enqueue_style(
        'theme-name-rtl',
        get_template_directory_uri() . '/css/rtl.min.css',
        array ( 'theme-name-default' )
    );
}

So the complete code is:

add_action( 'wp_enqueue_scripts',   't5_enqueue_style' );

function t5_enqueue_style()
{
    wp_enqueue_style(
        'theme-name-default',
        get_template_directory_uri() . '/css/default.min.css'
    );

    // extra RTL stylesheet

    if ( is_rtl() )
    {
        wp_enqueue_style(
            'theme-name-rtl',
            get_template_directory_uri() . '/css/rtl.min.css',
            array ( 'theme-name-default' )
        );
    }
}
-2
if ( is_rtl() ) {
  <link rel="stylesheet" type="text/css" href="<? bloginfo('template_directory');?>/style_rtl.css" />
} else {
  <link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
}
  • 4
    Never just print link elements. Use wp_enqueue_style(), so plugins can disable or replace the stylesheets per API. – fuxia Jul 19 '13 at 11:10
  • @toscho I think the question was about theme development not about plugins. Can you provide any case when developer need to replace stylesheet of the theme by his plugin ? – Lilumi Jul 19 '13 at 11:19
  • I have written some plugins for the Twenty X themes, there are also plugins for Genesis themes or other frameworks. – fuxia Jul 19 '13 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.