get_stylesheet_directory_uri 是你想要的。它返回当前主题的URL。get_stylesheet_directory 将返回服务器上的文件路径。
例如:
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/image.png" />
如果需要父主题,
get_template_directory 和
get_template_directory_uri 是等价物。
If there is no parent theme then both will return the same value.
进一步阅读:
get_template_directory<父主题的绝对文件夹路径,例如。/var/www/yoursite/wp-content/themes/parent_themeget_stylesheet_directory_uri<当前主题的完整URL,例如。https://example.com/wp-content/themes/child_themeget_template_directory_uri<父主题的完整URL,例如。https://example.com/wp-content/themes/parent_theme