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:

Read More
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?

Related posts

Leave a Reply

2 comments

  1. 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