PHP function return. Nested functions
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 "som开发者_高级运维ething".
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 need get_bloginfo()
rather.
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
精彩评论