I know there’s WordPress StackExchange, but that’s more PHP related question.
I’m writing my own shortcode for WordPress it looks like:
function myShortcode_shortcode() {
return 'something';
}
This shortcode displays simple string “something”.
The problem is I want to display an image from template directory:
<img src="<?php bloginfo('template_directory') ?>/images/myImage.jpg" alt="" />
And I don’t know how?
When I do:
return '<img src="'. bloginfo('template_directory') .'/images/myImage.jpg" alt="" />';
Script is echoing template directory instead of image.
Any ideas?
The problem is that the
bloginfo()
function is an output function (intended for templates). You needget_bloginfo()
rather.You probly need to place
<img src="<?php bloginfo('template_directory') ?>/images/myImage.jpg" alt="" />
in his own variable likeHope this helps