Support » Plugin: WP-LESS » compiled css path issue.

  • Hi,
    I am having issue with compiled css files path.

    I am using
    `if (class_exists(‘WPLessPlugin’)) {
    $lessConfig = WPLessPlugin::getInstance()->getConfiguration();

    // compiles in the active theme, in a ‘css’ subfolder
    $lessConfig->setUploadDir(get_stylesheet_directory() . ‘/css’);
    $lessConfig->setUploadUrl(get_stylesheet_directory_uri() . ‘/css’);
    to set my css path, good thing is its now saving compiled css files in my theme folder named “css”, but bad things is its somehow saving it inside
    my .less files exist inside /my-theme/less/

    Please suggest any solution. I have looked at code but was unable to trace how I can fix it without modifying core.

    I found this filter “wp-less_stylesheet_save” but not sure how I can use it to change path.

    Note: I am first registering my styles and then enqueue it. (not directly enqueueing without registering.


Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author oncletom


    Hm, I’m not sure to understand the issue you are encountering: you mean files are not compiled in .css?

    I was able to manage it my using

    add_filter('wp-less_stylesheet_compute_target_path', 'wp_less_stylesheet_compute_target_path');

    and the function is

    function wp_less_stylesheet_compute_target_path($target_path) {

    $theme = wp_get_theme();
    if (strstr($target_path, “/{$theme->template}/less/”) !== FALSE) {
    $target_path = str_replace(“/{$theme->template}/less/”, “/”, $target_path);
    if (strstr($target_path, “/{$theme->stylesheet}/less/”) !== FALSE) {
    $target_path = str_replace(“/{$theme->stylesheet}/less/”, “/”, $target_path);
    return $target_path;

    thanks for having a look. But I have another issue on my hand right now.

    I want to use “w3totalcache” with CDN, and for that I need my paths for images inside stylesheets to be relative but currently plugin is converting them to*.jpg,*.png which I don’t want, also I am using parent / child theme combo, so it will be awesome if I could save the compiled *.css files into their respective themes like

    *.less files from parent theme should go to parent theme path (specified by me) and same for child theme???

    Can I achieve it with your plugin????

    I’m also having some issues with the compiled path customization.

    I’m using the code right from the git repository:

    // wp-content/themes/your-theme/functions.php

    if (class_exists(‘WPLessPlugin’)){
    $lessConfig = WPLessPlugin::getInstance()->getConfiguration();

    // compiles in the active theme, in a ‘compiled-css’ subfolder
    $lessConfig->setUploadDir(get_stylesheet_directory() . ‘/compiled-css’);
    $lessConfig->setUploadUrl(get_stylesheet_directory_uri() . ‘/compiled-css’);

    What gets returned is below:

    <link rel=”stylesheet” id=”theme-main-css” href=”” type=”text/css” media=”all”>

    It looks like the plugin is adding the additional path info to href of the css. What I want to happen is have WP-Less compile the css and place in /Polynesian/compiled-css.

    My path to the less files are:
    wp_enqueue_style(‘theme-main’, get_stylesheet_directory_uri().’/library/less/style.less’);

    Any idea what’s going wrong??

    @mikemuller for that you should use above function which I am using myself to achieve similar result

    add_filter('wp-less_stylesheet_compute_target_path', 'wp_less_stylesheet_compute_target_path');
    function wp_less_stylesheet_compute_target_path($target_path) {
    $theme = wp_get_theme();
    if (strstr($target_path, "/{$theme->stylesheet}/library/less/") !== FALSE) {
    $target_path = str_replace("/{$theme->stylesheet}/library/less/", "/", $target_path);
    return $target_path;
    Plugin Author oncletom


    @mikemuller you seem to enqueue stuff the good way.

    I’d bet you have a customized blog URI somewhere and the plugin is getting messed with that.

    If you want to use a CDN, i recommend you using only the setUploadUrl(): it will save the compiled CSS file in the proper location and will render the proper CDN uri to the browser.

    @oncletom according to my research on this issue, it doesn’t seem to be related to “customized blog URI”, the plugin always append the the path to less file in front of desired path, like

    in @mikemuller case
    Desired / Required uri: get_stylesheet_directory_uri() . ‘/compiled-css’;
    Input uri: get_stylesheet_directory_uri().’/library/less/style.less’;
    Output uri: get_stylesheet_directory_uri() . ‘/compiled-css/Polynesian/library/less/style-3dda9dfecc.css’;

    and actual output uri should be:
    get_stylesheet_directory_uri() . ‘/compiled-css/style-3dda9dfecc.css’

    if if you noticed, plugin is appending the “less file” uri after the set output uri.

    Did I made myself clear??? If not ask for more clarification.

    Plugin Author oncletom


    Oh OK i got the point!

    Well it might be a replacement issue, something I’ve let passing through as I don’t recommend generating content outside the configured WordPress upload_dir; this is the sole directory supposed to be writeable at any moment.

    Have you spotted where in the code this problem is happening?


    Yes I understand that, and its valid implementation, but its not an ideal one, as not everyone would like to use .less files in live environment unless they have a strong reason to use it, most ideal situation usage is in development environment where developer don’t want to recompile files himself (want auto mode), and less files have more reasonable usage in development then live site. Anyway.

    Yes I noticed you let it pass, as your logic is users will be using it to output in uploads dir, but and that make sense for the output path as in uploads path appended with extra path which points out less file makes sense but when user manually configure the desired output path / uri then its not picking the requirements properly. Anyway here is the culprit code,

    public function computeTargetPath();

    $this->stylesheet->src (this is the culprit) as it picks the input less file path and replaced the initial path with which matches get_theme_root_uri() and leaves


    via code

    $target_path = preg_replace('#^'.get_theme_root_uri().'#U', '', $this->stylesheet->src);
        $target_path = preg_replace('/.less$/U', '', $target_path);

    and which being appended to output path as bellow

    protected function configurePath();
    $this->target_path = self::$upload_dir.$target_file;
    $this->target_uri = self::$upload_uri.$target_file;

    actually its appending the partial path of input less file (the starts after /my-theme/less/theme-main-%s.css ) instead it should be just doing something like this

    inside function computeTargetPath();

    $target_path = preg_replace(‘#^’.get_theme_root_uri().’#U’, ”, basename($this->stylesheet->src));

    getting the file name instead of its full uri, and ofcourse do it for cases when user manually set the output path, so you will have to put somekind of flag variable to check against whether user manually configures output path or not???

    make sense????? let me know if not.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘compiled css path issue.’ is closed to new replies.