Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Serve minified stylesheet when SCRIPT_DEBUG or WP_DEBUG is defined
<?php
/*
* Manage loading of theme styles
*/
add_action( 'after_setup_theme', 'child_load_stylesheet' );
function child_load_stylesheet() {
// First, remove the stylesheet
remove_action( 'genesis_meta', 'genesis_load_stylesheet' );
// Enqueue the new stylesheet at a later priority to trump WooCommerce
add_action( 'wp_enqueue_scripts', 'child_enqueue_main_stylesheet', 15 );
}
function child_enqueue_main_stylesheet() {
$stylesheet = get_stylesheet_directory() . '/style.css';
$cachebust = ( file_exists($stylesheet) ? filemtime($stylesheet) : mt_rand() );
$version = defined( 'CHILD_THEME_VERSION' ) && CHILD_THEME_VERSION ? CHILD_THEME_VERSION : PARENT_THEME_VERSION;
$handle = defined( 'CHILD_THEME_NAME' ) && CHILD_THEME_NAME ? sanitize_title_with_dashes( CHILD_THEME_NAME ) : 'child-theme';
// Serve minified stylesheet when SCRIPT_DEBUG or WP_DEBUG is false
if ( SCRIPT_DEBUG == true || WP_DEBUG == true ) {
wp_enqueue_style( $handle, get_stylesheet_directory_uri() . '/style.css', false, $cachebust );
}
else {
wp_enqueue_style( $handle, get_stylesheet_directory_uri() . '/style.min.css', false, $version );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment