0

I am trying to build a child theme that uses SCSS. However, every time I make changes and recompile my stylesheet, it gets overridden by the parent stylesheet. This is because, in the head of my site, the parent styles are loading after the child styles. I cannot for the life of me figure out how to get the child styles to load last. I've looked at similar questions here and elsewhere and I cannot get it to work. This is what I have in my parent theme in library > theme.php:

if (!function_exists('slam_scripts_and_styles')) { 
function slam_scripts_and_styles() {
  global $wp_styles; // call global $wp_styles variable to add conditional wrapper around ie stylesheet the WordPress way
  if (!is_admin()) {
    $theme_version = wp_get_theme()->Version;

    // register main stylesheet
    wp_enqueue_style( 'slam-stylesheet', get_template_directory_uri() . '/library/css/style.css', array(), $theme_version, 'all' );

  }
}
}

And this is in my child functions.php:

//Get UIC Child Theme Styles
function uic_styles() {

    wp_dequeue_style( 'slam-stylesheet', get_template_directory_uri() . '/library/css/style.css', array(), $theme_version, 'all' );

    wp_enqueue_style( 'uic-styles', get_stylesheet_directory_uri() . '/library/css/style.css' );
}
add_action( 'wp_enqueue_scripts', 'uic_styles', 10 );

Any help would be much appreciated. I feel like I've been banging my head against a wall for several hours.

  • I faced a similar issue recently and realized that it was because I had the parent theme active on the dashboard under Appearance > Themes instead of the child theme. Also confirm your file is in the child theme and not the parent theme. To troubleshoot, try seeing if you can add a stylesheet that's something other than style.csss it's not the same as the parent theme's. If you can enqueue a different stylesheet just fine - then it has something to do with style.css itself. – RachieVee Sep 16 '14 at 18:46
  • The child theme is active, and it will pick up unique styles. But any time I try to override an existing parent style, nothing happens because the parent file loads last. – mcography Sep 16 '14 at 19:03
  • get_stylesheet_directory_uri() refers to the path of your current project, so perhaps where you're dequeue-ing the stylesheet, you're pointing at the parent and not the child theme, therefore there is nothing for it to remove. Try changing that to: codex.wordpress.org/Function_Reference/… – RachieVee Sep 16 '14 at 19:14
  • But I am trying to dequeue the parent stylesheet... – mcography Sep 16 '14 at 19:20
  • Wait, you're already using get_template_directory_uri - can I ask what theme this is? – RachieVee Sep 16 '14 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.