Create a gist now

Instantly share code, notes, and snippets.

<?
// When WP_DEBUG is true (aka: while developing) use LESS client side
add_action('wp_head', 'ds_use_clientside_LESS',999);
function ds_use_clientside_LESS() {
if ( WP_DEBUG ) : ?>
<link rel="stylesheet/less" type="text/css" href="<?= get_template_directory_uri() . '/style.less' ?>" />
<script type="text/javascript">less = { env: 'development' };</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/2.7.1/less.min.js"></script>
<? endif;
}
// When WP_DEBUG is false (aka: live site, after LESS compiled) use compiled .css file
add_action( 'wp_enqueue_scripts', 'ds_make_scripts' );
function ds_make_scripts() {
if (! WP_DEBUG ) {
wp_register_style('main', get_template_directory_uri() . '/style.css', '', null);
wp_enqueue_style( 'main');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment