【发布时间】:2020-03-27 13:32:09
【问题描述】:
Wordpress 使用包含域名的绝对 URL(例如 <img src="https://example.com/cat.png">)加载所有资产和链接。
如何不包含域名?
我尝试editing the WP_CONTENT_URL 并更新WP_SITEURL/WP_HOME 没有成功。
有简单的方法吗?
【问题讨论】:
标签: wordpress
Wordpress 使用包含域名的绝对 URL(例如 <img src="https://example.com/cat.png">)加载所有资产和链接。
如何不包含域名?
我尝试editing the WP_CONTENT_URL 并更新WP_SITEURL/WP_HOME 没有成功。
有简单的方法吗?
【问题讨论】:
标签: wordpress
您可以通过简单的 WordPress 主题 URL 函数 get_template_directory_uri() 来做到这一点。请参阅以下链接。
https://developer.wordpress.org/reference/functions/get_template_directory_uri/
它将提供 WordPress 主题的完整路径。如果你的图片路径是这样的
\wp-content\themes\your-theme\assets\images\image.jpg
然后你可以得到如下图的路径。
<img src="<?php echo get_template_directory_uri() . '/assets/images/image.jpg'; ?>">
【讨论】: