Plugin URL in WordPress
April 2, 2025 · AI Conversations
User
plugin dir url
Assistant
In WordPress, to get the **URL of a plugin directory**, you can use the `plugins_url()` function. Here's a basic example:
<?php echo plugins_url(); ?>
But if you want the **URL to your specific plugin's directory**, you can pass the current file reference:
<?php echo plugins_url( '', __FILE__ ); ?>
Or if you want the URL to a file inside your plugin folder:
<?php echo plugins_url( 'assets/js/script.js', __FILE__ ); ?>
This will return something like:
https://yourdomain.com/wp-content/plugins/your-plugin/assets/js/script.js
Let me know if you're using this inside a function, class, or enqueue script — I can tailor the example for that too.