Im trying to add an extra CSS file to my wordpress theme

224 Views Asked by At

Im trying to add an extra CSS file to my wordpress theme and switch between them as i switch website languages.

I added this code to my header.php file

<?php if (ICL_LANGUAGE_CODE == "ar"): ?><link rel="stylesheet" href="myfile.css" type="text/css" media="screen" />
<?php endif; ?>

and it doesnt seem to work, do i need to add another piece of code in another file to work? Im using wpml plugin

1

There are 1 best solutions below

0
On

You can do this easily in the functions.php file of your theme.

path_to_your_theme/functions.php :

This method is the right method to add some CSS files to your theme :

function custom_scripts() {
 if(get_bloginfo( 'language' ) == "en-US"){
    wp_enqueue_style( 'us_css', get_template_directory_uri().'/css/style-us.css' );
 }
 elseif(get_bloginfo( 'language' ) == "fr-FR"){
    wp_enqueue_style( 'fr_css', get_template_directory_uri().'/css/style-fr.css' );
 }
 ...
}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );

I use wp_enqueue_style(), it's a safe way to add/enqueue a CSS style file to the wordpress generated page.

Codex page : http://codex.wordpress.org/Function_Reference/wp_enqueue_style