2014-12-03 97 views
0

我试图添加一个额外的CSS文件到我的WordPress主题,并切换它们,因为我切换网站语言。我试图添加一个额外的CSS文件到我的WordPress主题

我将此代码添加到我的header.php文件

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

,它似乎没有工作,我是否需要添加另一段代码在另一个文件中工作? 即时通讯使用wpml插件

+1

你能呼应了'ICL_LANGUAGE_CODE'看到它的价值呢? – MSTannu 2014-12-03 20:40:27

回答

0

您可以在主题的functions.php文件中轻松完成此操作。

path_to_your_theme/functions.php中:

这种方法是一些CSS文件添加到您的主题,正确的方法:

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'); 

我用wp_enqueue_style(),这是添加一个安全的方式/将一个CSS样式文件排入wordpress生成的页面。

食品页:http://codex.wordpress.org/Function_Reference/wp_enqueue_style

相关问题