LESS WordPress
<?php
// http://wordpress.stackexchange.com/questions/20876/less-css-enqueue-style-with-add-filter-to-change-rel-attribute
function enqueue_less_styles($tag, $handle) {
global $wp_styles;
$match_pattern = '/\.less$/U';
if ( preg_match( $match_pattern, $wp_styles->registered[$handle]->src ) ) {
$handle = $wp_styles->registered[$handle]->handle;
$media = $wp_styles->registered[$handle]->args;
$href = $wp_styles->registered[$handle]->src . '?ver=' . $wp_styles->registered[$handle]->ver;
$rel = isset($wp_styles->registered[$handle]->extra['alt']) && $wp_styles->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = isset($wp_styles->registered[$handle]->extra['title']) ? "title='" . esc_attr( $wp_styles->registered[$handle]->extra['title'] ) . "'" : '';
$tag = "<link rel='stylesheet' id='$handle' $title href='$href' type='text/less' media='$media' />";
}
return $tag;
}
add_filter( 'style_loader_tag', 'enqueue_less_styles', 5, 2);
<?php
// http://carlorizzante.com/development/quickly-use-less-wordpress-theme/
function load_LESS() {
$path = get_stylesheet_directory_uri() . '/lesscss/';
/* LESS stylesheet and less.js */
$output = "\n"."<!-- Loading LESS stylesheet and less.js -->"."\n";
$output .= '<link rel="stylesheet/less" type="text/css" href="' . $path . 'stylesheet.less' . '"/>' . "\n";
$output .= '<script type="text/javascript" src="' . $path . 'less.js"></script>' ."\n";
/* Auto refreshing the page when saving the stylesheet */
$output .= "\n" . "<!-- Autorefresh for LESS.js -->" . "\n";
$output .= '<script type="text/javascript">' . "\n";
$output .= ' less.env = "development";' . "\n";
$output .= ' less.watch();' . "\n";
$output .= '</script>' . "\n\n";
/* Printing on page */
print $output;
}
if ( ! is_admin()) add_action( 'wp_head', 'load_LESS' );