Skip to content

Instantly share code, notes, and snippets.

@blogjunkie
Last active August 30, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blogjunkie/b2270d50acf754504114aa967ea191e5 to your computer and use it in GitHub Desktop.
Save blogjunkie/b2270d50acf754504114aa967ea191e5 to your computer and use it in GitHub Desktop.
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