• Hi there,
    I’m making a child theme for an existing website that was already customized.
    It works, it is activated but the css files that I’ve transfered to the child theme don’t override the files of the parent theme.

    I have replicated the directory structure of the parent theme but it seems it’s not working.

    Can anyone give me a suggestion? How can I tell WordPress to use the files from the child theme?

Viewing 15 replies - 1 through 15 (of 16 total)
  • What theme is this site using? Can you post a link?

    Thread Starter Giulio Daprela

    (@daprela)

    It is a premium theme, Glider, but since the problem is quite general regarding the setup of child themes I hoped I could have some suggestions.

    http://realplace.tv/

    I want to know how it is possible that the child theme doesn’t override the parent theme, and if there is anything that I can do to force it

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    All of your CSS modifications go into your Child Theme style.css file and not some other stylesheet.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    There are other factors why your Child Theme may not override the parent theme which are specific to your theme, it wouldn’t hurt to first ask this to your commercial theme’s vendors.

    Without being able to see the code, it’s difficult to say, but here are some general things that might be causing a problem.

    • If a theme uses include_once() or require_once(), particularly in conjunction with get_template_directory_uri(), it’s probably not possible to override that particular included file in a child theme. If the theme author used locate_template() instead, then WordPress would search your child theme’s directory instead.
    • Come to think of it, the use of get_template_directory_uri() is problematic for child themes in general, because it will always use your parent theme’s directory.
    • If your theme does not make its functions pluggable (by wrapping them in if ( ! function_exists( 'foo' ) ) or hooking them in via add_action), you can’t override those functions in a child theme.
    • Depending on how the authors enqueued their stylesheets in wp_head(), your child theme’s stylesheet may load before any separately included stylesheets, meaning that any rules in your child theme’s stylesheet might be overridden by CSS rules defined in these extra stylesheets.
    Thread Starter Giulio Daprela

    (@daprela)

    Hi Andrew,
    so there’s no way to tell WordPress to use “my-style.css” in the child theme instead of that in the parent theme?

    What if I put the custom files in the child theme and then add to style.css

    @import url(“my-style.css”);

    would this work?

    That would work. You could also call wp_enqueue_style() in your child theme’s functions.php. Are you importing the parent theme’s stylesheet into your child theme’s stylesheet: @import url( '../parent-theme-directory/style.css' )?

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    so there’s no way to tell WordPress to use “my-style.css” in the child theme instead of that in the parent theme?

    Yes there is, but if the theme is set up properly your theme should automatically be doing this. I’m having to say “ifs” a lot because this is specific to your theme’s set up. Another way of doing it would be to dequeue your theme’s stylesheet (in your Child Theme functions.php file), IF your theme has enqueued it properly, and then enqueue your own.

    You really should be having this conversation with the people who gave you this theme.

    Thread Starter Giulio Daprela

    (@daprela)

    hi stephencottontail,
    the vendor provides a basic child theme. In it, there is this function in the functions.php file

    function crum_child_css() {
    	wp_enqueue_style( 'child-style', get_stylesheet_uri() );
    }
    
    add_action( 'wp_enqueue_scripts', 'crum_child_css', 51 );

    I thought that this would guarantee that the stylesheet files in the child theme would work

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I thought that this would guarantee that the stylesheet files in the child theme would work

    It does work, your Child Theme style.css file is loaded.
    You’re querying about other files you’ve added into your Child Theme aren’t you?

    but the css files that I’ve transfered to the child theme don’t override the files of the parent theme.

    Thread Starter Giulio Daprela

    (@daprela)

    Andrew and stephencottontail,
    this is going to be a topic to bookmark about child themes πŸ™‚

    The wp_enqueue_style function it’s always been a bit of a mistery to me. I’ve never been able to completely understand how it works.

    Now, what I’m getting is that I should add the same piece of code for each and every stylesheet that I want to use in the child theme, is that right?
    So, I should replace get_stylesheet_uri() with a function that finds the uri of the file – let’s say – my-stylesheet.css

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I’m not sure you need to do this. Why not just put your CSS modifications into your Child Theme style.css file?

    Thread Starter Giulio Daprela

    (@daprela)

    You are right Andrew,
    but there are a LOT of customizations, and the style.css file would be very big, so I’d prefer to avoid that

    Whoa. This has gone way over my head. Can someone back up and tell me whether there is a fix for my problem or not?

    I am using Twenty-thirteen as the theme. I wanted to use a child theme so that changes I make to the css don’t get fouled up when they update the theme. I used the codex directions. I made the child directory, adjusted the parent style.css with the child name, etc. like the codex told me to. I uploaded it to the child directory.

    This is where it went haywire. When I activated the child theme, I no longer had the options of changing colors, navigation, widgets, etc. I could only change the site title, tag line, and static front page. This was when I clicked the customize link in the activated child theme picture. When I clicked the customize link on the admin panel, the theme changed to twenty-fourteen.

    This is so weird! I don’t know who to ask or if there is any fix for it or not.

    Thanks for any help you can give.
    Imdiane

    I am sooo sorry! I had posted a similar titled post and thought this was being answered here. Please forgive my intrusion in your discussion.

    Blushing!
    imdiane

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Help please: child theme doesn't override parent theme’ is closed to new replies.