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

WordPress How to Build a WordPress Plugin Building a WordPress Plugin Settings Page Adding CSS to WordPress Plugin Settings Pages

Chris Hubbard
Chris Hubbard
2,253 Points

Difference between WP_PLUGIN_URL & plugins_url

Can someone help me understand why WP_PLUGIN_URL was used when linking to images, but plugins_url was used when loading the styles?

Aren't they both returning a path to our plugins directory? Are there situations when one should be used over the other?

1 Answer

Kevin Korte
Kevin Korte
28,149 Points

That's a good question. WP Codex says the WP_PLUGIN_URL is a constant used by plugins_url to find the correct path, but should not be used directly in plugins or themes.

http://codex.wordpress.org/Determining_Plugin_and_Content_Directories

And for the Codex for plugins_url in the notes section, it says it uses WP_PLUGIN_URL [edit] constant internally, to compose the resultant URL. Note that direct usage of WordPress internal constants is not recommended.

http://codex.wordpress.org/Function_Reference/plugins_url

Maybe things have changed since these lessons were made? I'm just starting to get into plugin writing after becoming comfortable with theme development, so I too am curious as to why this is, just so we understand how to make our own good decisions later on projects.