Reputation: 1539
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?
Upvotes: 1
Views: 389
Reputation: 145482
The problem is that the bloginfo()
function is an output function (intended for templates). You need get_bloginfo()
rather.
Upvotes: 2
Reputation: 336
You probly need to place <img src="<?php bloginfo('template_directory') ?>/images/myImage.jpg" alt="" />
in his own variable like
function shortcode(){
$shortcode = "<img src='". bloginfo('template_directory') ."/images/myImage.jpg' alt="" />"
return $shortcode;
}
Hope this helps
Upvotes: 0