Support » Themes and Templates » Enqueue Styles for Child Theme In Addition to Style.css

  • Resolved -wp-user-

    (@-wp-user-)


    Hi there,
    I am relatively new to child themes and the enqueue scripts function.
    I am trying to implement on a child theme, but I am running into an issue with not being able to load addition child theme stylesheets to style.css.

    My style.css is loading fine, in addition to the custom.js.
    The other three stylesheets are not loading.
    I’m not sure what I’m doing wrong.

    <?php
    add_action( 'wp_enqueue_scripts', 'load_my_child_styles', 20 );
    function load_my_child_styles() {
        wp_enqueue_style('queen-bootstrap-min',get_stylesheet_directory_uri() . '/css/bootstrap.min.css', array());
    	wp_enqueue_style('queen-style', get_stylesheet_directory_uri() . '/style.css', array());
    	wp_enqueue_style('queen-responsive',get_stylesheet_directory_uri() . '/css/responsive.css', array());
    	wp_enqueue_style('queen-dark', get_stylesheet_directory_uri() . '/css/dark.css', array());
    	wp_enqueue_script('queen_scripts',get_stylesheet_directory_uri() . '/js/custom.js', array());
    }
    ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator stephencottontail

    (@stephencottontail)

    get_stylesheet_directory_uri() refers to the current theme’s folder, so you’d have to copy the css/ folder from the parent theme’s folder to the child theme’s folder. Another option would be to use get_template_directory_uri() which, when used in a child theme, refers to the parent theme’s folder.

    Thanks for your help.

    The styles/scripts I have listed are all included in my child theme, in the css folder. They are still not loading on the site, though, it is calling the stylesheets from the parent theme instead.

    Oddly, it is loading the style.css from my child and the custom.js, just not bootstrap.min.css or responsive.css or dark.css.

    Moderator stephencottontail

    (@stephencottontail)

    I’m sorry, I believe I may have misunderstood your first post. Are the stylesheets bootstrap.min.css, responsive.css, and dark.css not loading at all, or is WordPress loading the versions from the parent theme when you would like WordPress to load the versions from the child theme?

    No prob, I appreciate your help.

    The second: WordPress is loading the versions from the parent theme when I would like WordPress to load the versions from the child theme.

    Except for the style.css and custom.js. WordPress is loading the child versions of those two files, but loading the parent version for the others.

    Moderator stephencottontail

    (@stephencottontail)

    What parent theme are you using?

    Does it work if you change queen-bootstrap-min, queen-responsive, and queen-dark to queen-child-bootstrap-min, etc.?

    Huzzah! That fixed it.
    I added queen-child-“” to everything but custom.js and style.css and it is working now.

    Thanks so much for your help

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Enqueue Styles for Child Theme In Addition to Style.css’ is closed to new replies.