开发者

PHP Wordpress quotes issue

开发者 https://www.devze.com 2023-02-24 05:20 出处:网络
Having a quotes issue, need a second pair of eyes! echo \"<img src=\'\" . bloginfo(\'template_url\') . \"img/\" . $f[\'mainImage\'] . \".png\' />\";

Having a quotes issue, need a second pair of eyes!

echo "<img src='" . bloginfo('template_url') . "img/" . $f['mainImage'] . ".png' />";

Using the Wordpress function bloginfo to get the theme path!

All i'm getting is the path printed out on the page, no image!

Thanks

What开发者_如何学C is output:

 http://www.example.co.uk/wp-content/themes/example
<img src="/img/digital.png">


The function bloginfo() performs its own echo.

http://codex.wordpress.org/Function_Reference/bloginfo

In your situation, you would use this code:

echo "<img src='"; bloginfo('template_url'); echo "img/" . $f['mainImage'] . ".png' />";


bloginfo() is only used to directly output the requested value. Use get_bloginfo() instead to work with the value before echo'ing it.

echo sprintf(
    '<img src="%s/img/%s.png" />', 
    get_bloginfo('template_url'), 
    $f['mainImage']
);


As jnpcl has surmised, it looks like bloginfo() is print out the data for you.

You've got two options:

  • use the get_bloginfo() function, which wont just print it out but return it instead
  • Take that into account, echo part of the image tag, call the function, echo the rest
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号