我正试图从我的html/css网站创建我自己的WP主题。我设法迁移了html/css,但图像不会显示。
我意识到我必须更改img src路径,但我是否也必须添加som-php?
这条路是什么样子的?
谢谢!
这些图像是主题的一部分吗?如果是这样,那么我建议在主题的根目录(即wp-content/themes/[theme]/images
)中创建一个名为images
或类似的目录(我见过一些人使用assets
)。
然后你应该能够使用get_template_directory_uri()
访问它们,就像这样:
<img src='<?php get_template_directory_uri(); ?>/images/your-image.ext'>
如果您正在创建子主题,并且希望允许覆盖父主题图像,请将get_template_directory_uri()
替换为get_stylesheet_directory_uri()
。
参考文献
get_template_directory_uri()
get_stylesheet_directory_uri()
- 子主题