位置
为了让 WordPress 将一组主题模板文件识别为有效主题,style.css 文件必须位于主题的根目录中,而不能是子目录。
有关如何在主题中包含 style.css 文件的更详细解释,请参阅 Enqueuing Scripts and Styles的“Stylesheets”部分。
基本结构
WordPress 使用 style.css 的文件头注释部分来在外观(主题)仪表板面板中显示有关主题的详细信息。
示例
以下是 style.css 文件头的示例。
/*
Theme Name: Twenty Twenty
Theme URI: https://wordpress.org/themes/twentytwenty/
Author: the WordPress team
Author URI: https://wordpress.org/
Description: Our default theme for 2020 is designed to take full advantage of the flexibility of the block editor. Organizations and businesses have the ability to create dynamic landing pages with endless layouts using the group and column blocks. The centered content column and fine-tuned typography also makes it perfect for traditional blogs. Complete editor styles give you a good idea of what your content will look like, even before you publish. You can give your site a personal touch by changing the background colors and the accent color in the Customizer. The colors of all elements on your site are automatically calculated based on the colors you pick, ensuring a high, accessible color contrast for your visitors.
Tags: blog, one-column, custom-background, custom-colors, custom-logo, custom-menu, editor-style, featured-images, footer-widgets, full-width-template, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready, block-styles, wide-blocks, accessibility-ready
Version: 1.3
Requires at least: 5.0
Tested up to: 5.4
Requires PHP: 7.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: twentytwenty
This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/WordPress 主题存储库使用此文件中“Version”之后的数字来确定是否有新版本的主题可用。说明
标记为 (*)的项目是 WordPress 主题存储库中主题所需的。
- Theme Name (*): 主题的名称。
- Theme URI: 用户可以找到有关该主题更多信息的公共网页 URL。
- Author (*): 开发该主题的个体或组织的名称。建议使用 Theme Author 在 wordpress.org上的用户名。
- Author URI: 作者个人或组织的 URL。
- Description (*): 主题简介。
- Version (*): 主题的版本,格式为 X.X 或 X.X.X。
- Requires at least (*): 该主题将与之配合使用的最旧的 WordPress 主版本号,格式为 X.X。仅要求支持最近三个版本的主题。
- Tested up to (*): 该主题测试过的最后一个主要 WordPress 版本,即 5.4。只写数字,格式为 X.X。
- Requires PHP (*): 支持的旧版 PHP 版本号,格式为 X.X,仅包含数字。
- License (*): 主题的许可证类型。
- License URI (*): 主题许可证的 URL。
- Text Domain (*):用于翻译的文本域字符串。
- Tags: 允许用户通过标签过滤器找到该主题的单词或短语。完整的标签列表在 Theme Review Handbook中。
- Domain Path: 用于让 WordPress 知道禁用主题时在哪里查找翻译文件。默认为
/languages。
在必需的文件头部分之后,style.css可以包含任何常规 CSS 文件中有的内容。
子主题的 style.css
如果您的主题是子主题(Child Theme),则必须在 style.css文件头的Template行中指定模板名称。
/*
Theme Name: My Child Theme
Template: twentytwenty
*/有关创建子主题的更多信息,请访问 Child Themes页面。