-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5782a6
commit 9e28347
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
date: 2024-12-03 16:34 | ||
slug: WordPress图片相对地址 | ||
--- | ||
|
||
可以使用WordPress内置的函数`get_site_url()`来生成相对地址。修改图片标签如下: | ||
|
||
<!-- truncate --> | ||
|
||
|
||
|
||
```html | ||
<img src="<?php echo get_site_url(); ?>/wp-content/uploads/2024/12/mpwechat.jpg" alt="微信公众号二维码"> | ||
``` | ||
|
||
这样无论是在本地环境还是生产环境,地址都会自动适配当前站点URL。使用相对地址是更好的做法,因为迁移网站时不需要手动修改地址。 |