簡體   English   中英

我正在嘗試向我的WordPress主題添加一個額外的CSS文件

[英]Im trying to add an extra CSS file to my wordpress theme

我試圖在我的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生成的頁面中的安全方法。

Codex頁面: http : //codex.wordpress.org/Function_Reference/wp_enqueue_style

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM