我正在使用来自 http://html5blank.com 的 Wordpress 主题,当我将它上传到我的在线服务器时效果很好,但是当我使用 Wordpress Bitnami Stack 在本地使用它时,主题找不到 css。在 header.php 中你有:
<!-- css + javascript -->
<?php wp_head(); ?>
但是当我在本地主机上查看开发站点的源代码时(激活主题后),我发现 css 的 href
是空的:
<!-- css + javascript -->
<link rel='stylesheet' id='normalize-css' href='' media='all' />
<link rel='stylesheet' id='html5blank-css' href='' media='all' />
同时它确实找到了图像和图标:
<!-- icons -->
<link href="http://localhost:8080/wordpress/wp-content/themes/html5blank-master/img/icons/favicon.ico" rel="shortcut icon">
<link href="http://localhost:8080/wordpress/wp-content/themes/html5blank-master/img/icons/touch.png" rel="apple-touch-icon-precomposed">
我的操作系统是 Ubuntu 12.10。这可能是 Bitnami 问题,还是我可以解决这个问题以便我可以在本地网站上工作?请注意,默认主题“twentytwelve”在我的设置中运行良好。
更新:我在我的 Bitnami Wordpress 堆栈中比较并尝试了 html5blank 主题的 1.2.9 和 1.4.0(当前版本)版本。就wp_register_style()
而言,两个版本的functions.php
文件是相同的,但是1.2.9 版填写了指向css 的链接,而1.4 版。 0 将它们留空。另请注意,1.4.0 在 Windows 7 上的 Bitnami 安装中运行良好。
最佳答案
问题是主题设计中的一些代码与在非标准端口号上运行的 WordPress 之间的交互。
我追踪到向 WordPress 的 esc_url
函数报告的函数 wp_kses_bad_protocol
wp-includes/class.wp-styles.php
) 样式表 URL 的协议(protocol)无效。 esc_url
是为了防止恶意内容进入 URL;其中一项检查是查看是否有任何可疑的东西,例如 javascript:
协议(protocol)而不是 http:
。
一个问题的误检似乎是html5blank主题为过滤器style_loader_src
添加了一个过滤器函数html5blank_protocol_relative
引起的。总的来说,这似乎不是一件坏事(protocol relative 基本上意味着将 http://whatever...
替换为 //whatever...
,这避免了在同一页面上混合使用 https 和 http 的问题——//whatever
的“协议(protocol)相关”URL 将根据需要使用 https 或 http。)
但是,当您在特定端口号上运行 WordPress 时,这似乎会混淆不良协议(protocol)检测。
长话短说:您可能想将此报告给主题的开发人员,让他知道正因为如此,他的主题在非标准端口上运行 WordPress 时中断,即使用像 这样的 URL http://localhost:8080/wordpress
,而不是 http://localhost/wordpress
。
在短期内,我只是注释掉这些行:
add_filter('script_loader_src', 'html5blank_protocol_relative'); // Protocol relative URLs for enqueued scripts
add_filter('style_loader_src' , 'html5blank_protocol_relative'); // Protocol relative URLs for enqueued styles
...在主题的 functions.php
中;那应该关闭协议(protocol)相对 URL 过滤,并且您的主题应该在本地工作。除非您的实时网站使用 https,否则它们也应该可以很好地适应这一变化,即使它们确实使用 https,您的情况也不会比大多数现有主题更差。
关于css - Wordpress 主题找不到 CSS(本地主机),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16021673/