WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

I've done a lot of research and learned a lot about WP constants and function usage for getting image paths etc. but still my original problem persists.

<img src="<?PHP echo WP_PLUGIN_DIR . 'vertical-social-buttons/images/facebook.png'?>">

<img src="<?PHP echo WP_PLUGIN_DIR . 'vertical-social-buttons/images/facebook.png'?>">

<img src="<?PHP echo plugins_url('vertical-social-buttons/images/facebook.png', __FILE__);?>">

All give me broken images. Am I missing something obvious?

share|improve this question
Check out this stackoverflow.com/questions/3128873/… – Diana Jul 31 '12 at 0:28
up vote 2 down vote accepted

Use plugin_dir_url() to get the public URI for the directory where the calling PHP file is.

<img src="<?php echo plugin_dir_url( __FILE__ ) . 'images/facebook.png'; ?>">

If the PHP file is in a sub directory of your plugin you have to go up:

<img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . 'images/facebook.png'; ?>">
share|improve this answer
That still gives me a broken image. Does plugin_dir_url( FILE ) give me a URL into plugins/MYPLUGIN/ ? I've tried about 15 different methods now and still broken images. – BenRacicot Jul 31 '12 at 15:05
Yes, it returns the URL to the directory of the calling file with a trailing slash. – toscho Jul 31 '12 at 15:07
I've got it! plugin_dir_url( FILE ) gives a URL path inside the file it is being used on. As in the actual file you're coding in. My images folder was not within this folder. Learned a lot. Thank you very much. – BenRacicot Jul 31 '12 at 15:34
@user1440240 I made an update to my answer to make that point more clear. – toscho Jul 31 '12 at 15:39

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.