douhoushou8385 2017-05-11 15:01
浏览 50

如何在Wordpress中覆盖CSS

I'm trying to create a Wordpress child theme, but I can't seem to get it to override styles in the parent theme.

functions.php

<?php

if ( ! function_exists( 'my_theme_enqueue_styles' ) ) {
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
}

/**
 *    WP Enqueue Stylesheets
 */
if ( ! function_exists( 'rev_cust_enqueue_stylesheets' ) ) {
    add_action( 'wp_enqueue_scripts', 'rev_cust_enqueue_stylesheets' );

    function rev_cust_enqueue_stylesheets() {
        wp_enqueue_style( 'rev-main', get_template_directory_uri() . '/layout/css/rev_main.css', array(), '', 'all' );
    }
}

?>

rev_main.css

#header .top-header .header-navigation ul li {
    margin-left: 40px;
    line-height: 1.375;
    font-weight: normal !important;
    font-size: 1px;
    color: #fff;
    text-transform: uppercase;
    position: relative;
    float: left;
 }

Why isn't my style class not being picked?

Thank you all in advance.

UPDATE

  1. I don't think the css file even gets picked up,
  2. I have the child theme enabled.
  • 写回答

1条回答 默认 最新

  • doutuo6048 2017-05-11 15:23
    关注

    The problem was at:

    get_template_directory_uri()
    

    in:

    /**
     *    WP Enqueue Stylesheets
     */
    if ( ! function_exists( 'rev_cust_enqueue_stylesheets' ) ) {
        add_action( 'wp_enqueue_scripts', 'rev_cust_enqueue_stylesheets' );
    
        function rev_cust_enqueue_stylesheets() {
            wp_enqueue_style( 'rev-main', get_template_directory_uri() . '/layout/css/rev_main.css', array(), '', 'all' );
        }
    }
    
    ?>
    

    This points to the parent theme, instead of the child theme.

    It should be get_stylesheet_directory_uri as follows:

    function rev_cust_enqueue_stylesheets() {
        wp_enqueue_style( 'rev-main', get_stylesheet_directory_uri() . '/layout/css/rev_main.css', array(), '', 'all' );
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题