每个类别的标题背景颜色不同

时间:2018-04-10 23:29:47

标签: php wordpress header background-color

我想为类别更改标题的不同背景颜色。该类别为https://afdigitale.it/category/af-gaming。我在functions.php中使用此代码,但它不起作用:



<?php
if (is_category ('6933')) {?>
<style="background-color:black">
<?php
}
?>
&#13;
&#13;
&#13;

THX

1 个答案:

答案 0 :(得分:1)

取决于您的主题使用的是什么类,这对我来说很有用。我将它连接到了 site-content-contains 类,它是2016 WordPress主题中的主要内容容器。将此代码添加到主题的 functions.php 文件中。

add_action( 'wp_head', 'add_css_head' );

function add_css_head() {
    if ( is_category( 6933 ) ) {
        ?>
        <style type="text/css">.site-content-contain{background-color:black;}</style>
        <?php
    }
}