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:

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.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!