Use stylesheet from a different location

I haven’t done wordpress development in quite some time so it looks like some things have changed (naturally). I’m using codekit to compile my themes sass files and minify my scripts as well. It requires that all files have a specific output path, in other words I can’t specify that the style.scss file should compile to a style.css file in the root directory. It has to go into a folder of some sort relative to the root folder, like a /css folder.

So in googling around trying to see if there was a way to tell wordpress to look into the /css folder and look for a file called site.css I found this code I can add to my functions.php file…

Read More
add_filter('stylesheet_uri','wpi_stylesheet_uri',10,2);

/**
 * wpi_stylesheet_uri
 * overwrite default theme stylesheet uri
 * filter stylesheet_uri
 * @see get_stylesheet_uri()
 */
function wpi_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri){

    return $stylesheet_dir_uri.'/css/site.css';
}

Now if I’m not mistaken it looks like I have to call that function? But when I try to call it, say in my header.php I get an error.

To summarize I am looking for the preferred way to change where wordpress looks for my themes stylesheet.

Related posts

Leave a Reply

2 comments

  1. Create a theme’s style.css as normal but just include the header information. This will be a config file only.

    The register and enqueue your stylesheet(s). You can use any path you’d like. I think this is what you need:

    function register_theme_styles() {
        wp_register_style( 'theme-styles', site_url( '/css/site.css' ) );
        wp_enqueue_style( 'theme-styles' );
    }
    add_action( 'wp_enqueue_scripts', 'register_theme_styles' );
    
  2. You can use this filter, to filter out styles with any condition, or change output href string, example:

    add_filter( 'style_loader_src', function($href){
    if(strpos($href, "name-of-allowed.css") !== false) {
    return $href;
    }
    return false;
    });