简体   繁体   English

WP函数的回声问题

[英]echo issue with WP function

I am new WP user and please forgive me for any mistakes when explaining my issue. 我是WP的新用户,在解释我的问题时,如有任何错误,请原谅我。

I am having an issue with "echo". 我对“回声”有疑问。 Here is the situation. 这是情况。

<?php echo '<p><img src="' . bloginfo('stylesheet_directory') . '/images/img-1.jpg" /></p>' ?>

When I am trying the above code, the output is totally different. 当我尝试上面的代码时,输​​出完全不同。 The url is displaying outside the <p> tag. 网址显示在<p>标记之外。

Like this 像这样

http://127.0.0.1/wp/wp-content/themes/ThemeName<p><img src="/images/img-1.jpg" /></p>

But simple use like this - is working great. 但是像这样的简单使用-效果很好。 Why the above is not working? 为什么以上方法不起作用?

<figure><img src="<?php bloginfo('stylesheet_directory'); ?>/images/img-1.jpg" /></figure>

You need to use get_bloginfo to return a string which you can concatenate, bloginfo echo's automatically (in this case, while the echo string is being constructed, thus being echoed before the rest of the string). 您需要使用get_bloginfo返回一个可以连接的字符串, bloginfo echo会自动连接(在这种情况下,正在构造echo字符串时,将在其余字符串之前回显)。

<?php echo '<p><img src="' . get_bloginfo('stylesheet_directory') . '/images/img-1.jpg" /></p>' ?>

Alternately, you could do this: 或者,您可以执行以下操作:

<p><img src="<?php bloginfo('stylesheet_directory'); ?>/images/img-1.jpg" /></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM