• Does anyone have an example of how to change the location of the default style.css file by using the add_filter function?

Viewing 7 replies - 1 through 7 (of 7 total)
  • if you want to change the style.css url add the below code inside your theme’s functions.php

    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/mytheme.css';
    }

    if you need to change the theme’s stylesheet directory only

    add_filter('stylesheet_directory_uri','wpi_stylesheet_dir_uri',10,2);
    
    /**
     * wpi_stylesheet_dir_uri
     * overwrite theme stylesheet directory uri
     * filter stylesheet_directory_uri
     * @see get_stylesheet_directory_uri()
     */
    function wpi_stylesheet_dir_uri($stylesheet_dir_uri, $theme_name){
    
    	$subdir = '/css';
    	return $stylesheet_dir_uri.$subdir;
    
    }

    taken from http://code.google.com/p/wp-istalker/source/browse/branches/WordPress/2.7/1.6.2/lib/modules/filters.php#326

    Thread Starter solidhex

    (@solidhex)

    Ah, nice. Thanks chaoskaizer!

    Thread Starter solidhex

    (@solidhex)

    This seems to work initially, but when I add page templates, they are not found. Then, when I visit the ‘Theme’ page it says the theme style sheet is missing and reverts to the the default theme. This seems odd, as the link is correct and the design of the site is fine prior to visiting the theme section.

    Has this happened to anyone else?

    Thread Starter solidhex

    (@solidhex)

    Has anyone else had this problem? changing the location of the style sheets makes the theme inactive if you are in theme section of the wp-admin?

    Thread Starter solidhex

    (@solidhex)

    Anyone else had an issue with this?

    I googled here and tried the code above, It works well.

    To solve the “the theme style sheet is missing” problem, just write some theme info only in a file, named style.css and put in your theme directory.

    Forgive me for bad English.

    Thread Starter solidhex

    (@solidhex)

    HI xwingyz,

    Yes I did that, and it worked 😉 I was just curious if there was a way to get around have to create the extra style.css file in the theme’s root directory.

    I don’t think there is…

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Changing location of style.css with filters’ is closed to new replies.