How to link to graphic assets within WordPress Plugins
When you want to display graphics that reside inside your own plugin directory you can serve those via a handy built-in WordPress function called plugins_url. It works just like its counterpart get_stylesheet_directory_uri does in themes.
For example, if you’d like to link to a file that resides at
then you can write this URL out like so:
<?php echo plugins_url('images/your-graphic.png', __FILE__); ?>
Note the usage of the PHP constant __FILE__ (that’s two underscores before and after FILE), it’s called a Magic Constant. In this case it points to your own plugin’s directory. If you leave this parameter out you’ll get the URL to the main plugins directory.
If instead you’d like to access the full server path to this file rather than its URL, you can use the plugin_dir_path function.