I'm writing a plugin for wordpress and am having trouble with images. If I have my plugin in wp-content/plugins/my-plugin/ and in there, a folder images/test.png - how do I reference that image in my code? I don't want to have to put the images in to the theme, as when other users come to get my plugin, the image won't work!
so my structure is
myplugin/plugin.php (which includes several files...)
myplugin/pluginstyle.css
myplugin/includes/page.php
myplugin/images/test.png
I have the style sheet working nicely, but when I try and use an image as the background for an element it doesnt work.
How do I reference the image in my plugin?
test output from page.php
<div class="test"><p>hello</p></div>
css
.test { background: url(../images/test.png) repeat-x; }
where am I going wrong? Is there a method which I should be using? Thanks for any help!
One way to do this is:
plugins_url('images/test.png', __FILE__)
...which will give you the correct URL even if the user has changed the name of the parent directory.
I used Collin's answer in this way:
<img src="<?php echo plugins_url( 'images/test.png', __FILE__ ); ?>" border="0" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With