我正在尝试向我的 wordpress 主题添加一个额外的 CSS 文件,并在我切换网站语言时在它们之间切换。
我将此代码添加到我的 header.php 文件中
<?php if (ICL_LANGUAGE_CODE == "ar"): ?><link rel="stylesheet" href="myfile.css" type="text/css" media="screen" />
<?php endif; ?>
它似乎不起作用,我需要在另一个文件中添加另一段代码才能工作吗? 我正在使用 wpml 插件
最佳答案
您可以在主题的 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
关于php - 我正在尝试向我的 wordpress 主题添加一个额外的 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27280077/