I am trying to use child themes for the first time in Wordpress - and I've got it working (at least from a user's perspective - it functions correctly)

My concern is that both the parent and child CSS files are loaded - so I'm concerned about performance. Ideally, I just want the child's CSS file used.

My code in functions.php is the following - does anyone have any suggestions how to just rely on the min.css file from the child template?

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' ); 
function my_theme_enqueue_styles() {

    $parent_style = 'johannes-style'; 

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/assets/css/min.css', array(), wp_get_theme()->get('Version'));
    wp_enqueue_style( 'johannes-child-main', get_stylesheet_directory_uri() . '/assets/css/min.css', array( $parent_style ), wp_get_theme()->get('Version')); 

Thanks in advance!

  • If you don't want the paren't theme's stylesheet, just remove that line, and remove it as a dependency of the child theme, You can just enqueue the one stylesheet if you want. – Jacob Peattie Feb 21 at 16:16
  • I do that but the original stylesheet from the parent still shows? – sitestem Feb 21 at 16:40
  • Your parent theme is likely still enqueuing it (which is slightly odd because parent themes normally enqueue the child theme's stylesheet when one is active). You will need to use wp_dequeue_style to remove it, but you'll need to find the original handle inside the parent theme to know what to use. – Jacob Peattie Feb 22 at 6:04
  • Yep that solved the problem thanks! Just needed to dequeue the script – sitestem Feb 22 at 17:07

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.