0

I want to create a child theme (of Twentysixteen in this example) and load my stylesheet with a cache busting string. So I did the following:

function my_theme_enqueue_styles() {
$stylesheet_version = filemtime(get_stylesheet_directory() . '/style.css');
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style'), $stylesheet_version );   
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

This works, but as the parent theme also loads my child theme stylesheet, it gets loaded twice. I want to get rid of that second call to the same stylesheet, like so:

function remove_repeated_style(){
wp_dequeue_style('twentysixteen-style');
}

My question is: where can I hook this function to make it run after the parent theme functions have run? I have tried: 'after_setup_theme', 'wp_print_styles' and 'wp_enqueue_scripts' with a very late priority (which seems to have worked for some people, but not for me).

  • Can you look up the code in the parent theme which registers the styles you want to remove? How does your parent theme load child theme's stylesheet? Normally a parent theme isn't aware of the child theme. – rocknrollcanneverdie Jan 16 '17 at 15:30
0

You have to do:

function remove_repeated_style(){
  wp_dequeue_style('twentysixteen-style');
}
add_action( 'wp_enqueue_scripts', 'remove_repeated_style', 11 );

The 11 is important.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.