admin管理员组

文章数量:1122826

So I am developing a wordpress theme using a series of LESS files for the CSS. These compile using codekit to a combined and minifed stylesheet that I use for the theme's styling.

I understand a wordpress theme must have a style.css which includes the info about the theme in its comments, but is it required to link this style.css in the header.php? Surely I can just have the theme info in it and nothing else and leave it untouched in the theme folder. The stylesheet I actually use can just be called styles.css or main.css or something.

can anyone confirm this or give reasons why this might be a bad idea?

So I am developing a wordpress theme using a series of LESS files for the CSS. These compile using codekit to a combined and minifed stylesheet that I use for the theme's styling.

I understand a wordpress theme must have a style.css which includes the info about the theme in its comments, but is it required to link this style.css in the header.php? Surely I can just have the theme info in it and nothing else and leave it untouched in the theme folder. The stylesheet I actually use can just be called styles.css or main.css or something.

can anyone confirm this or give reasons why this might be a bad idea?

Share Improve this question asked Aug 22, 2013 at 16:26 harrygharryg 7635 gold badges11 silver badges23 bronze badges 1
  • 1 You should leave the style.css with theme infos at the root of your theme folder. That's it. – JMau Commented Aug 22, 2013 at 16:37
Add a comment  | 

5 Answers 5

Reset to default 17

I would say: you should not use the style.css for the actual production CSS.

The reason is simple: minification. You cannot minify the content of the file completely, because WordPress has to read it. In my themes, I use style.css just for the headers, and I add a comment, explaining where to find the real CSS, so other developers don’t have to search too long.

Example:

/*
Theme Name:    My theme name
Version:       2013.08.24
License:       MIT
Text Domain:   t5_theme
Domain Path:  /lang

You will find the real stylesheet in css/default.css.
*/

You are correct, Harry, that you do not need to actually call to or load the default style.css in your header file. Since I've been using SCSS in my themes, I've encountered this same issue, but had decided to maintain the link to style.css for the following reasons which may or may not be applicable to your situation:

  • Default WP assumptions are that style.css exists and is in use, and I don't want to thwart that assumption with respect to plugins. I don't know if/when this would be an issue and would be interested to hear others' experiences and advice on this point.
  • If my actual in-use stylesheet is in a folder, it prevents users from being able to edit the site's CSS. Keeping style.css active and available gives my users a way to still be able to make CSS changes from the WP admin.
  • Related, while working on the staging site with other partners, if they don't also use SCSS, they can make changes to style.css without affecting my ability to continue to use my SCSS files.

Again, these points may not be applicable to your situation but have informed my decision to keep the default style.css linked, even if it's mostly blank except for the required theme info.

Yes, WordPress uses the theme's style.css as a "config" document.

You are also correct, as far as I can tell, that you don't have to actually load style.css on the front end in order to have it serve its "config" purposes.

What you are doing should be fine. I am pretty sure I have seen other themes do something similar but I can't swear to it. The only issue I can see would be if some plugin erroneously assumes that style.css is the (only) stylesheet in the theme.

You could also add this to your config.rb (if you're using Compass) and CodeKit will automatically copy your minified stylesheet to style.css in the theme root.

require 'fileutils'
on_stylesheet_saved do |file|
  if File.exists?(file) && File.basename(file) == "style.css"
    puts "Moving: #{file}"
    FileUtils.mv(file, File.dirname(file) + "/../" + File.basename(file))
  end
end

I use this with every WordPress theme I develop and it works like a charm.

Make sure that the comment in your style.scss file starts with the ! after the opening comment or else it will be removed in the minification:

/*!
  Theme Name: Your Theme

Source: CSS-Tricks

you can just add this in your function.php

wp_enqueue_style('theme-style', get_template_directory_uri() . '/css/style.css');

本文标签: Do I actually need to link my theme39s stylecss in the theme files