WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Parent Theme Over Riding Child Theme Every Time (5 posts)

  1. Elymnesis
    Member
    Posted 8 months ago #

    I'm new to WordPress, and I'm having trouble with child themes. I'm eagerly trying to learn the system, and the problem I'm consistently having is that none of my child themes override my parent themes. They are displayed as crossed out in the developer tools.

    The only thing I'm trying to change right now is the color of the header. What am I doing wrong?

    Here is my site:

    Help would be very deeply appreciated.

  2. stephencottontail
    Member
    Posted 8 months ago #

    Your theme is calling an additional stylesheet named black.css after your child theme's main stylesheet. The styles in black.css are overriding your color rules in your child theme's stylesheet. A quick fix would be to use !important in your child theme's stylesheet.

  3. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 8 months ago #

    You are doing nothing wrong, actually. Part of the reason that your child theme isn't overriding the color is, as stephen stated, the second stylesheet is being loaded.

    There are several ways of going about this and they all depend on how comfortable you are with code and editing files.

    == Version one ==
    1. Create a header.php file and remove the line:

    <link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />

    2. Create a functions.php file and add:

    add_action( 'wp_enqueue_scripts', 'child_style' );
    function child_style(){
        wp_enqueue_style( 'parent', PC_THEME_ROOT_URI . '/style.css' );
        wp_enqueue_style( 'child', get_stylesheet_uri(), array( 'parent', 'color-scheme-stylesheet' ) );
    }

    == Version Two ==
    1. Create a header.php file and move the line:

    <link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>" type="text/css" media="screen" />

    after <?php wp_head(); ?>

    == Version three ==
    1. use !important on all the rules that are being a pain in the tushy.

  4. Elymnesis
    Member
    Posted 8 months ago #

    Thank you very much for the help! Jose, I used both of your first two solutions and both worked perfectly. I'm going to continue to use the first version, because I'm guessing it's the most standard, or you wouldn't have mentioned it first. (I have experience in CSS and HTML, but PHP is new to me.)

    I also didn't know about !important. What a great command. This should help me very much.

    Thank you thank you thank you!

  5. Jose Castaneda
    THEME COFFEE MONKEY
    Posted 8 months ago #

    Happy to help.

    Yes, the first is sort of a standard when it comes to stylesheets and scripts and is standard theme review guidelines. Part of that reason is so that if any child themes or plugins rely on certain scripts/styles won't misbehave. :)

Reply

You must log in to post.

About this Topic