Last active
December 11, 2015 21:58
-
-
Save kopepasah/4665849 to your computer and use it in GitHub Desktop.
Use LESS in a live WordPress theme.
This file contains 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 | |
if ( ! function_exists( 'less_filter_stylesheet_uri' ) ) { | |
function less_filter_stylesheet_uri( $stylesheet_uri, $stylesheet_dir_uri ) { | |
$current_user = wp_get_current_user(); | |
if ( $current_user->ID == '1' ) | |
$src = $stylesheet_dir_uri . '/style.less'; | |
else | |
$src = $stylesheet_dir_uri . '/style.min.css'; | |
return $src; | |
} | |
add_filter( 'stylesheet_uri', 'less_filter_stylesheet_uri', 10, 2 ); | |
} |
This file contains 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 | |
if ( ! function_exists( 'less_add_theme_stylesheet' ) ) { | |
function less_add_theme_stylesheet() { | |
$current_user = wp_get_current_user(); | |
if ( ! builder_disable_theme_stylesheets() ) { | |
if ( $current_user->ID == '1' ) | |
echo '<link rel="stylesheet/less" href="' . get_stylesheet_uri() . '" type="text/css" media="screen" />' . "\n"; | |
else | |
echo '<link rel="stylesheet" href="' . get_stylesheet_uri() . '" type="text/css" media="screen" />' . "\n"; | |
} | |
} | |
add_action( 'builder_add_stylesheets', 'less_add_theme_stylesheet', 0 ); | |
} |
This file contains 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 | |
if ( ! function_exists( 'less_enqueue_scripts' ) ) { | |
function less_enqueue_scripts() { | |
$current_user = wp_get_current_user(); | |
/** | |
* Let's enqueue less to use in the for me | |
* only. That is user ID 1 or user kopepasah. | |
*/ | |
if ( $current_user->ID == '1' ) | |
wp_enqueue_script( 'lesscss', get_stylesheet_directory_uri() . '/js/less.min.js' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'less_enqueue_scripts' ); | |
} |
This file contains 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 | |
if ( ! function_exists( 'less_remove_stylesheets' ) ) { | |
function less_remove_stylesheets() { | |
remove_action( 'builder_add_stylesheets', 'builder_add_theme_stylesheet', 0 ); | |
} | |
add_action( 'init', 'less_remove_stylesheets' ); | |
} |
This file contains 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
lessc --yui-compress style.less > style.min.css |
This file contains 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 | |
$current_user = wp_get_current_user(); | |
if ( $current_user->ID == '1' ) | |
echo '<link rel="stylesheet/less" href="' . get_stylesheet_uri() . '" type="text/css" media="screen" />' . "\n"; | |
else | |
echo '<link rel="stylesheet" href="' . get_stylesheet_uri() . '" type="text/css" media="screen" />' . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment