Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I instruct wordpress to use a filename other than 'styles.css' for my main stylesheet - for example, styles-1.css? I'd like to do this for versioning and caching purposes.

share|improve this question
add comment

7 Answers

up vote 4 down vote accepted

Style.css is required for your WordPress theme. That's where WordPress gets the theme name and meta information for the Appearance >> Themes menu from. That said, you don't actually have to use style.css in your theme at all. I know of several readily available themes that don't use it, and I only use it in a handful of my custom designs.

In header.php just place the following tag in place of the regular stylesheet link:

<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/style-1.css" />

This will load your alternative stylesheet as the page's stylesheet and completely ignore the regular style.css.

share|improve this answer
Just to clarify, you DO have to have a style.css file in your WordPress theme with the theme name in it. You DON'T have to load that file in your header.php file. –  Doug Aug 12 '10 at 16:58
And you shouldn't put your styles in theme files directly - use wp_enqueue_style instead - it's much nicer for child themes and plugins. –  Krzysiek Dróżdż Dec 11 '13 at 20:58
add comment

This may be inappropriate, please let me know if I missed something.

The fourth argument to wp_enqueue_style() is the stylesheet's version number. In your theme's functions.php:

function my_theme_styles() {
    // replace "10" with your version number; increment as you push changes
    wp_enqueue_style('my-theme-style', get_bloginfo('template_directory') . '/style.css', false, 10);
add_action('wp_print_styles', 'my_theme_styles');

Requires that your header.php does a wp_head(), which of course you were doing anyway. ;)

This allows you to push long expiry headers with your CSS file, and force clients to download a new file by updating the version number. WP will append "?ver=N" to the URL of your CSS file.

share|improve this answer
add comment

Drop this in your theme's functions.php file:

function my_cool_style_versioner( $style ){
  return str_replace( '/style.css', '/style-1.css', $style );

add_filter( 'stylesheet_uri', 'my_cool_style_versioner' );
share|improve this answer
Presumably, I would need to call that function from somewhere ... (and I assume the missing / is a mistake!) –  Bobby Jack Aug 11 '10 at 23:10
Yes, that missing slash was a mistake, and I added the filter hook you'll need to use too. –  John P Bloch Aug 11 '10 at 23:18
Also, note that as you increase the version, the second argument ('/style-1.css') will change, but the first one ('/style.css') will always stay the same. –  John P Bloch Aug 11 '10 at 23:23
amazing, we should create plugin for this! –  ariefbayu Aug 12 '10 at 0:07
add comment

EAMann is correct, you don't have to use the style.css file for all your CSS.

For versioning the style sheet and other files in your theme you can add this to your functions.php file

function fileVersion($filename)
    // get the absolute path to the file
    $pathToFile = TEMPLATEPATH.'/'.$filename;
    //check if the file exists
    if (file_exists($pathToFile)) 
        // return the time the file was last modified
        echo filemtime($pathToFile);
        // let them know the file wasn't found
        echo 'FileNotFound';

And then when you make the link to your style sheet you can do this.

<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>?v=<?php fileVersion('style.css'); ?>" />

This way you don't have to manually update the version number, anytime the file is updated on the server the version will automatically change to that UNIX timestamp

share|improve this answer
add comment

Well, you could simply use style.css as the place where you call the version you want. Simply put

@import url("style-1.css");

Then when you upgrade a version, just edit it to be:

@import url("style-2.css");

As for saving versions, have you considered using a Subversion, or git? Then you can have a complete track record of your stylesheet. It's possible I'm not fully understanding the full reasons for your versioning.

share|improve this answer
add comment

I'm not sure if this has changed for WP3, so I'm not wholly sure, but one way is to edit the relevant php file directly (I don't know if it can be done from within the Dashboard/Admin pages):


And open up header.php. In this file find this line:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

To add a 'version' to the linked stylesheet (assuming you want it to be something like: stylesheetURL.css?version=2) change it to:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>?version=2" type="text/css" media="screen" />

This is kind of inelegant, though, so if there's a better way I'd love to hear it myself =)

I just re-read your question...

To use a different stylesheet styles-1.css you can either just the (above) line to:

<link rel="stylesheet" href="absolute/or/root-relative/path/to/styles-1.css" type="text/css" media="screen" />

(Basically removing the <?php ... ?> and replacing it with a regular path.)

share|improve this answer
"This is kind of inelegant, though" - yeah, particularly if I want to use a file named "style-1.css"! ;-) –  Bobby Jack Aug 11 '10 at 23:11
@Bobby Jack, agreed and +1 (though I did try and add a similarly inelegant approach to achieve your aim.) =/ –  David Thomas Aug 11 '10 at 23:13
OK. I guess I was concerned that stylesheet_url might be used elsewhere, but there's really no reason for that, is there? There's also the fact that it would be nice to have some mechanism for automating the update to always use the most recent file version, but I'm just starting to expose flaws in my question now :) –  Bobby Jack Aug 11 '10 at 23:27
add comment

I know that this thread is rather old by now. But in case someone needs a quick solution. There is a plugin called Versions which handles versioning of stylesheets and scripts automatically. Get it at: http://wordpress.org/extend/plugins/versions/

share|improve this answer
You must disclose your affiliation in your answers. And please use just one account on our site. –  toscho Dec 13 '12 at 13:18
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.