Archived topic
Prioritize External Stylesheet
3 replies · Started by Matthew on October 27, 2019
Recently, I've run into a situation where the CSS edit environment in the Customizer takes precedence over the external style.css file. I've not experienced this in GP until very recently. Mostly, but not exclusively, the precedence takes place with WooCommerce styles.
Is there a way I can prioritize so that the things so that style.css takes precedence over the Customizer stylesheet editor?
I tried the following, but without success:
add_action( 'wp_enqueue_scripts', 'generate_remove_scripts' );
function generate_remove_scripts()
{
wp_dequeue_style( 'generate-child' );
}
add_action( 'wp_enqueue_scripts', 'generate_move_scripts', 999 );
function generate_move_scripts()
{
if ( is_child_theme() ) :
wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' );
endif;
}
Thank you.
Hi there,
By default child theme style sheets are enqueued after the customizer inline styles.
So this could mean that the styles within your child theme style sheet are not specific enough. Woo's CSS Selectors are a highly ( overly ) specific.
If you can provide me with a password i can take a look.
I actually think the Customizer CSS is added to wp_head, so it shows up later: https://github.com/WordPress/WordPress/blob/5.2.4/wp-includes/default-filters.php#L298
https://github.com/WordPress/WordPress/blob/5.2.4/wp-includes/default-filters.php#L282
You could move the Customizer CSS to 0 priority, but that might not be a great idea:
add_action( 'wp', function() {
remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
add_action( 'wp_head', 'wp_custom_css_cb', 0 );
} );