WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hoping someone can answer this!

I'm using

<img src="<?php echo get_template_directory_uri(); ?>/images/image.jpg">  

for my header and it is working. But when I try to use it in a sidebar text widget it won't show the image. Any ideas??


share|improve this question

PHP code won't run inside of a text widget. There are plugins that will let you do that, but this type of thing is strongly discouraged.

Add this code to your functions.php file, or better yet, make it a simple little plugin:

// Enable the use of shortcodes within widgets.
add_filter( 'widget_text', 'do_shortcode' ); 

// Assign the tag for our shortcode and identify the function that will run. 
add_shortcode( 'template_directory_uri', 'wpse61170_template_directory_uri' );

// Define function 
function wpse61170_template_directory_uri() {
    return get_template_directory_uri();

To use it in the admin, add the shortcode [template_directory_uri] to your text widget, and the template directory will be output e.g.

share|improve this answer
Thank you! Worked like a charm! – Susan Aug 8 '12 at 22:56
No prob, and welcome to WPSE! Could you please click the check mark to accept this answer? Thanks, and cheers! – goto10 Aug 8 '12 at 23:30

You can use a php widget, which is a plain text widget adapted to be able to execute php. See WordPress › PHP Code Widget « WordPress Plugins by http://ottodestruct.com

share|improve this answer

A simple solution would be to upload the image to media, and use the url as the src for the image in the text widget.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.