1

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?

1
  • What does the "shortcode" part have to do with the "template directory" part? Commented Mar 22, 2011 at 12:25

2 Answers 2

2

The problem is that the bloginfo() function is an output function (intended for templates). You need get_bloginfo() rather.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.