LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » WordPress / WordPress Snippets » How To Get WordPress Plugin’s Path And URL For Plugin Writing?

How To Get WordPress Plugin’s Path And URL For Plugin Writing?

How-To-Get-WordPress-Plugins-Path-And-URL-For-Plugin-Writing
Writing a WordPress plugin is soo easy that everyone can write it but when it comes to use the correct code on correct place then its time for professionals coders but don’t worry you can also. Like writing a plugin, you have to link your plugin with added resources but whats the way to liked them because everyone have different path and URLs so you have to use their URLs to link your resources.

Before, endless exertion was made in deciding the area of a plugin, including the way and the URL. It was genuinely an agony to figure the right index that a plugin fits in with (speculating does imply that it can not be right frequently, you know). Such dreary errand is no more an issue as of WordPress 2.8. In form 2.8, two valuable capacities were presented, to be specific plugin_dir_url() and plugin_dir_path(), both can be placed in wp-incorporates/plugin.php.

To use those two functions, all you need to do is to pass a __FILE__ parameter which is basically the path to the main PHP file of your plugin. Yet another path, eh? Fortunately getting this path is much more easier than guessing the whole thing.

Table of Contents

How To Add Correct Plugin Folder Path/URL?

echo plugin_dir_url( __FILE__ );
 // Output something like: http://example.com/wp-content/plugins/your-plugin/
echo plugin_dir_path( __FILE__ );
 // Output something like: /home/mysite/www/wp-content/plugins/your-plugin/

If you happen to use this code in a PHP file inside a sub-folder, simply use more d functions, like so:

This way all the paths and URLs should be correct (even if you install your plugin as a must-use plugin. plugin_dir_url() and plugin_dir_path() will automatically add a trailing slash to the URL and path so please keep that in mind when you try to append something (to avoid the double slashes issue.

Last Words:

This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *