WordPress.org

Forums

Changing location of style.css with filters (8 posts)

  1. solidhex
    Member
    Posted 6 years ago #

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

  2. chaoskaizer
    Member
    Posted 6 years ago #

    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

  3. solidhex
    Member
    Posted 6 years ago #

    Ah, nice. Thanks chaoskaizer!

  4. solidhex
    Member
    Posted 6 years ago #

    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?

  5. solidhex
    Member
    Posted 6 years ago #

    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?

  6. solidhex
    Member
    Posted 6 years ago #

    Anyone else had an issue with this?

  7. xwingyz
    Member
    Posted 6 years ago #

    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.

  8. solidhex
    Member
    Posted 6 years ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic