Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WP-Less compiling? WordPress


Having trouble with WP-Less (Sanchothefat version - - not OncleTom version) compiling as I need it to compile a few different less files and then output them with the file titles as bootstrap-green.css, bootstrap-red.css, etc.

assets > css > less > bootstrap-green.less
compile to
assets > css > bootstrap-green.css

assets > css > less > bootstrap-red.less
compile to
assets > css > bootstrap-red.css

assets > css > less > bootstrap.less
compile to
assets > css > bootstrap.css

assets > css > less > responsive.less
compile to
assets > css > responsive.css

It currently just compiles into one roots_bootstrap.css file (and one roots_bootstrap_responsive.css) and sends it to the theme folder. (I added Noel Tock's filter - - to get WP-Less to send results to the theme folder, but am unsure how to modify it to move it to the assets > css folder).

The reason for needing it to compile multiple versions is to allow for a theme option switcher (and offline compiling is not an option unfortunately).

Here's what's included in functions.php to enqueue the styles

if ( of_get_option('altstylesheet') == 'green' ) {
wp_enqueue_style('roots_bootstrap', get_template_directory_uri() . '/assets/css/less/bootstrap-green.less', false, null);
elseif ( of_get_option('altstylesheet') == 'red' ) {
wp_enqueue_style('roots_bootstrap', get_template_directory_uri() . '/assets/css/less/bootstrap-red.less', false, null);
else {
//Blue is default
wp_enqueue_style('roots_bootstrap', get_template_directory_uri() . '/assets/css/less/bootstrap.less', false, null);
wp_enqueue_style('roots_bootstrap_responsive', get_template_directory_uri() . '/assets/css/less/responsive.less', false, null);
wp_enqueue_style('roots_font_awesome', get_template_directory_uri() . '/assets/css/font-awesome.css', array('roots_bootstrap'), null);
wp_enqueue_style('roots_app', get_template_directory_uri() . '/assets/css/app.css', false, null);

It's at for now.

Answers (1)


WisdmLabs answers:

Hi Christopher ,

Try following modifications in Noel Tock's filter.

add_filter( 'wp_less_cache_path', 'my_less_cache_path' );
add_filter( 'wp_less_cache_url', 'my_less_cache_url' )

function my_less_cache_path( $path ) {
return get_stylesheet_directory().'/assets/css';

function my_less_cache_url( $url ) {
return get_stylesheet_directory_uri().'/assets/css';

Essentially, I have just added the /assets/css which should work.