Coo*_* Yo 2 directory wordpress themes
我有以下代码,我期待它做的是找到我正在使用的主题并在/images/bg.png之前放置该路径到目前为止我只是获取localhost/nameoffolder/images/bg.png的位置但我想要的是localhost/nameoffolder/wp-content/themes/images/bg.png
<img src="<?php get_template_directory(); ?>/images/bg.png"></img>
Run Code Online (Sandbox Code Playgroud)
这是我想要显示的目录 http:// localhost:8888/fiftyfity/wp-content/themes/fiftyfity/images /
我使用这个代码而且它有效
<img src="<?php bloginfo( 'template_directory' ); ?>/images/bg.png"></img>
Run Code Online (Sandbox Code Playgroud)
get_template_directory()返回目录,但它不回显它..所以如果你使用它与echo它将工作
<img src="<?php echo get_template_directory(); ?>/images/bg.png"></img>
Run Code Online (Sandbox Code Playgroud)
但我建议改用get_template_directory_uri(),因为上面不能移植(windows使用反斜杠作为分隔符)
<img src="<?php echo get_template_directory_uri(); ?>/images/bg.png"></img>
Run Code Online (Sandbox Code Playgroud)