Wordpress 默认样式表路径 [英] Wordpress default stylesheet path

查看:50
本文介绍了Wordpress 默认样式表路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以更改默认的 Wordpress 样式表路径?当我将 style.css 移动到/styles/style.css 文件夹(并更新 header.php 中的路径)时,我无法从管理面板加载我的主题,因为 WP 尖叫着模板损坏:-/

Is there any way to change default Wordpress stylesheet path? When I move style.css to /styles/style.css folder (and updating path in header.php) I cannot load my theme from admin panel, because WP screams about broken template :-/

我尝试在 functions.php 中使用 define('STYLESHEETPATH', get_template_directory . '/css'); 但它不起作用.

I tried with define('STYLESHEETPATH', get_template_directory . '/css'); in functions.php but it doesn't work.

推荐答案

必须在你的主题文件夹中有一个 style.css 因为这是 WordPress 使用标题中的注释识别主题的方式这个文件的.如果您想在不同的子目录中托管实际的 CSS,最简单的方法是进行 CSS 导入:

You must have a style.css in your theme folder since this is how WordPress identifies the theme, using the comments in the header of this file. If you wanted to host the actually CSS in a different subdirectory the easiest way would be to do a CSS import:

文件style.css

File style.css

/*  
Theme Name: My Theme
*/
@import url('css/style.css');

文件css/style.css

File css/style.css

* { margin: 0; padding: 0 }
body { font-size:12px; }

您也可以显式加载这两个文件,但我建议使用上面示例中的方法.

You can also explicitly load both files, but I would recommend the way in the example above.

不建议更改 STYLESHEETPATH,因为许多插件使用它来确定活动主题的路径,但是在您的示例中,您缺少对 get_template_directory() 的函数调用的括号.

Changing the STYLESHEETPATH isn't recommend since many plugins use this to determine the active theme's path, however in your example you are missing the parens for the function call to get_template_directory().

这篇关于Wordpress 默认样式表路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆