Created
July 12, 2017 01:52
-
-
Save hellofromtonya/fed1ba52e761a57cdd50deb51eac701a to your computer and use it in GitHub Desktop.
A better version of our code to change the theme's stylesheet URL to the minified one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// code left out for brevity | |
add_filter( 'stylesheet_uri', 'change_theme_stylesheet_uri_to_min_version', 9999, 2 ); | |
/** | |
* Change the theme's stylesheet URI to minified version when not | |
* in development/debug mode. | |
* | |
* @since 1.0.0 | |
* | |
* @param string $stylesheet_uri Stylesheet URI for the current theme/child theme. | |
* @param string $stylesheet_dir_uri Stylesheet directory URI for the current theme/child theme. | |
* | |
* @return string | |
*/ | |
function change_theme_stylesheet_uri_to_min_version( $stylesheet_uri, $stylesheet_dir_uri ) { | |
if ( site_is_in_debug_mode() ) { | |
return $stylesheet_uri; | |
} | |
$minified_stylesheet_filename = '/style.min.css'; | |
if ( ! file_exists( get_stylesheet_directory() . $minified_stylesheet_filename ) ) { | |
return $stylesheet_uri; | |
} | |
return $stylesheet_dir_uri . $minified_stylesheet_filename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment