Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


How to properly reference image paths in WordPress

How do you input the source for img tags in the content area of a page for a local WP site? Right now I have <img style="width: 100%;" src="images/live-session.jpg" alt="image1" /> but that only shows a big white rectangle where the image should have been. I also tried <img style="width: 100%;" src="http://localhost/samplesite.com/wp-portfolio/images/live-session.jpg" alt="Class in Action!" /> and that didn't work either. Is there some trick for localhost I'm missing here?

Edit: Meh, never mind, I'll just upload the pictures. It's easier that way anyway.

1 Answer

Shaker Advertising
Shaker Advertising
5,395 Points

If you're trying to reference pictures, lets say, from an image directory within your theme you can use the following SRC path:

<img src="<?php echo get_stylesheet_directory_uri(); ?>/path-to-your-image-folder-within-your-theme/image.jpg" />

You can also set the WP function as global variable for easier reference.

Hope that helps.