skip to Main Content

this is driving me insane.

child theme .css is loaded, after the parent style, but the CSS is just not applied / doesn’t override, I’ve searched around and I see several other people complaining about this.

Enqueing the style or even adding priority to it does not solve it.

Adding the same CSS via the theme customizer, the CSS is actually applied, so the CSS itself is not the problem here.

What can I do more?!

2

Answers


  1. Chosen as BEST ANSWER

    I finally found an enque setting that solves it,

    function my_theme_enqueue_styles() { 
    
    wp_register_style( 
        'child-style', 
        get_stylesheet_directory_uri() . '/style.css', 
        array(), 
        filemtime( get_stylesheet_directory() . '/style.css' ) 
      );
    
      wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
      wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array('parent-style') );
    }
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    

    apparently what made a difference for me is the "array('parent-style')" value in the function atributes, must investigate it further but this was the only thing that solved it.


  2. Have you included a dependency in the wp_enqueue_script()?

    /**
     * Proper way to enqueue scripts and styles
        Example...
     */
    function wpdocs_theme_name_scripts() {
        wp_enqueue_style(
            'stylesheet-name', // it will append '-css' in your source
            get_template_directory_uri() . '/css/stylesheet-name.css',
            array('parent-style'), // dependants (reliable on other stylesheet)
            'null',  // version, null or version number (1.0.1 etc)
            'all' // media
        );
    }
    add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
    

    Note: if you have a version number in your enqueue then the cache could stop it from loading. Some people use date() to change the value each time it refreshes…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search