Does anyone happen to know how I can automatically turn:
http://www.example.com/wp-content/themes/theme-name/css/stylesheeet.css
into
http://www.example.com/css/stylesheet.css
Naturally I could just create the applicable folder within the root of the website, place the files there and just reference them but that is now what I am after.
I am looking for a way to keep all CSS & JavaScript files within the theme folder but I would like for wordpress to show the above outlined url path if you view the source of the page.
In an ideal situation I am looking for a piece of code which can be added that automatically does this for all files referenced within my theme folder including any images.
Offhand I think you’d need two things:
First, a rewrite rule in your .htaccess file like so:
Second, add a filter to your theme’s functions.php like so:
A couple caveats:
– if a plugin or something doesn’t use bloginfo() or get_bloginfo() it will not trigger the filter. You can get around this by hooking your function into other filters as needed.
– some plugins/themes/etc use a hard-coded paths. There’s not much you can do about this except modify the code to use one of WP’s functions to get the path.
Here’s the same example using the twentyten theme (no css/js subdirectories, but the idea is the same.)
.htaccess
functions.php
I am going to propose an alternate solution that will solve the problem.
Create a symbolic link from wp-content/themes/your-theme to your root directory/css
To create a symbolic link in Linux use the
#ln -s
command. For example:Now any file in http://example.com/wp-content/themes/your_theme_name/ can be accessed using the url:
http://example.com/css/
In order for this to work you have to allow the FollowSymLinks directive in your httpd.conf file. You can also put it in an .htaccess file that will override the setting in httpd.conf
In httpd.conf the setting would be:
Before the change will take affect you will have to restart Apache:
You can read more about SymLinks at Maxi-Pedia and in the Apache Docs