Skip to content

WPML RTL Child Theme - unique style sheet for RTL version?

1 minute read

If you are using in the same time:

  • WPML plugin
  • At least one RTL language
  • Child theme

You can change default function.php file in your child theme to have separate additional sheet for RTL version (RTL version will use both MyHome Child files - style.css and style-rtl.css )

  1. 1 Please open your /wp-content/themes/myhome-child/ folder
  2. 2 Create style-rtl.css file
  3. 3 Backup function.php file
  4. 4 Replace old function.php file with this new one:
php
<?php

function myhome_child_enqueue_styles() {
    $options           = get_option( 'myhome_redux' );
    $dependency_parent = array();
    $dependency_child  = array( 'myhome-style' );
    if ( ! is_rtl() ) {
        $parent_style = '/style.min.css';
    } else {
        $parent_style = '/style-rtl.min.css';
    }
    if ( ! isset( $options['mh-performance_css'] ) || empty( $options['mh-performance_css'] ) ) {
        $dependency_parent[] = 'normalize';
        $dependency_child[]  = 'normalize';
        if ( ! is_rtl() ) {
            $parent_style = '/style.css';
        } else {
            $parent_style = '/style-rtl.css';
        }
    }

    wp_enqueue_style( 'myhome-style', get_template_directory_uri() . $parent_style, $dependency_parent, My_Home_Theme()->version );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', $dependency_child, My_Home_Theme()->version );

    if ( is_rtl() ) {
        wp_enqueue_style( 'myhome-custom-rtl', get_stylesheet_directory_uri() . '/style-rtl.css', array( 'myhome-style' ), My_Home_Theme()->version );
    }
}

add_action( 'wp_enqueue_scripts', 'myhome_child_enqueue_styles' );

function myhome_lang_setup() {
    load_child_theme_textdomain( 'myhome', get_stylesheet_directory() . '/languages' );
}

add_action( 'after_setup_theme', 'myhome_lang_setup' );

Ask the people who build MyHome WPBakery

We answer by email from support@tangiblewp.com. With Premium Support, we also fix your site when something breaks.

Was this guide helpful?