18

I am new to MAMP and I am developing a theme I designed. However I can't seem to get the images to render. I am using a clear theme I got from starkerstheme.com When adding an image directly to the code I used:

<img src="<?= $theme ?>/images/logo.png"/>

But the image is not showing up, also I tried to add it to the media library and it's still not rendering.

Andrew Irwin
  • 691
  • 12
  • 40
Sophie
  • 329
  • 2
  • 7
  • 19

8 Answers8

28

This works for me:

<img src="<?php echo get_bloginfo('template_url') ?>/images/logo.png"/>

See get bloginfo() function for more info.

Robert Zelník
  • 850
  • 7
  • 16
11

You can use the following code to add an image. This works for me:

<img src="<?php echo get_template_directory_uri(); ?>/images/filename.png">
g00glen00b
  • 41,995
  • 13
  • 95
  • 133
ismail
  • 111
  • 1
  • 3
7
<?php echo get_template_directory_uri(); ?> 

as suggested gets the PARENT theme, which is OK but if you've developed a child theme (as recommended by WordPress people) you need:

<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/Logo.png">
Zac
  • 4,510
  • 3
  • 36
  • 44
demsley
  • 319
  • 3
  • 6
3

Just go to your dashboard and upload your picture in the media section, then select it you'll see the image options .. then copy it's url <img src="your/copied/url"/> This aslo works for me in localhost

Mina Ragaie
  • 457
  • 6
  • 17
2

<?php bloginfo('template_directory'); ?>/

use for internal root folder in images to place on theme on wordpress. The forward slash is needed for the image to show

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
chef1974
  • 21
  • 1
2

You might need to do the full <img src="<?php echo $theme; ?>/images/logo.png"/>

Update I didn't read your question closely enough. If you're using the media library for the image, you'll need to specify the actual path to the image. You can figure this out from within the media library, but it's probably site_url/wp-content/uploads/2012/01/filename.jpg

In short, if you uploaded it in media, it wouldn't actually be in your theme.

Eve Freeman
  • 32,467
  • 4
  • 86
  • 101
0

on 2021...

Just name the image as screenshot.png [ recommended image size (currently) is 1200px wide by 900px ] and put it on theme's top-level directory (where the style.css file is )

and that's all you need to do.

Ale DC
  • 1,646
  • 13
  • 20
0

Remove the = after <?

<img src="<? $theme ?>/images/logo.png"/>

in fact, I'd probably do something like this:

<img src= <?php $theme ?> . "/images/logo.png"/>

Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
  • `=` is a short tag that isn't available on all servers. That's why I thought you might have trouble with it. Are you sure `$theme` is defined? – Paul Dessert Jan 17 '12 at 01:39
  • I guess not, how do I define it? – Sophie Jan 17 '12 at 01:54
  • You'll have to post more of your code in order to answer that question. – Paul Dessert Jan 17 '12 at 01:56
  • = is a short tag that replaces won't display anyting. Unless $theme is not defined, and the web server echoes warnings (which it should not in production). – Cedric Jun 11 '13 at 17:11
  • when you are using a child theme. Use get_template_directory_uri() function instead of et_stylesheet_directory_uri() is you use the parent theme. – Cedric Jun 11 '13 at 17:17