使用 WordPress 网站时如何使用相对 URL
关于如何设置 wordpress 使用相对 url 有任何提示或建议吗?
Are there any tips or suggestions on how to set up wordpress to use relative urls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我编写了一个小 PHP 函数,该函数位于主题的functions.php 文件中:
在主题文件中使用它,如下所示:
I wrote a little PHP function that I located in the functions.php file of my theme:
Using it in the theme files like this:
例如,您指的是编辑器插入图像的时间吗?
如果是这样,那么我不知道有任何配置设置可以阻止 WordPress 添加完整 URL(例如 mysite.com/wp-content/uploads/image1.jpg),但您有机会在单击“确定”之前对其进行编辑。
Are you referring to when the editor, for example, inserts images?
If so, then I am not aware of any configuration setting to stop WordPress adding the full URL (eg. mysite.com/wp-content/uploads/image1.jpg) but you have the opportunity to edit it before clicking OK.
是的,您可以使用我的插件: http://wordpress.org/extend/plugins/ root-relative-urls/
它将所有 url 转换为根相对路径,包括通过编辑器嵌入的 url。它甚至会将 rss 提要转换回绝对提要(这只是必要的,因为像 feedburner 和 feedblitz 这样的公司不遵循 html 规范。)
在撰写本文时存在的插件缺乏对代码库的完整覆盖。它们仅处理特定的网址或特定的场景。而且您永远不必搜索和查找替换你的数据库,Tim Berners Lee 早在 1993 年就解决了这个问题。
希望有所帮助,抱歉我无法早点回答这个问题,但直到一个月前左右我才写了这个插件:D
Yep, you can use my plugin: http://wordpress.org/extend/plugins/root-relative-urls/
It will convert all urls to root relative, including urls that are embedded via the editor. It will even convert rss feeds back to absolute (which is only necessary because companies like feedburner and feedblitz don't follow the html spec.)
The plugins that exist at the time of writing this lack complete coverage of the codebase. They only handle specific urls or specific scenarios. And you should never have to search & replace your database, Tim Berners Lee solved that problem way back in 1993.
Hope that helps and sorry I couldn't answer this question sooner, but I didn't write the plugin until a month ago or so :D