WordPress generate urls dynamically, 使用数据库中的数据。It is up to themes/plugins to use wordpress functionalities to generate urls instead of hardcoding them.
Wordpress has a series of functions that are supposed to be used when dealing with urls, 其中一些是:
get_template_directory_url (主题url)plugin_dir_url (插件url)get_stylesheet_directory_url (样式表url)
例如,当您放置
<a href="">Menu Item</a> 在主题模板中
href 锚的属性
shoudn\'t have a hardcoded url 喜欢
localhost:8080/link-to/the-post, 相反
you should use get_post_permalink() (如果我们处理的是帖子),则返回帖子的相对url。
如果必须使用位于my-theme/assets/img/my-img.png, 你可以创作这个图像src 使用get_template_directory_url, 不要硬编码文件夹主题的url:
<img src="<?php echo get_template_directory_url(); ?>/assets/img/my-img.png"/>
The same goes to files paths. 如果站点从服务器移出,硬编码路径将失败。
Wordpress provides functions like