Get Current Plugin URL in WordPress

Today, We want to share with you Get Current Plugin URL in WordPress.In this post we will show you How to Link to Your WordPress Theme and Plugin Resources, hear for wordpress get current plugin directory path we will give you demo and example for implement.In this post, we will learn about wordpress get current plugin root directory with an example.

Get Current Plugin URL in WordPress

There are the Following The simple About Current Plugin URL in wp Full Information With Example and source code.

As I will cover this Post with live Working example to develop get link wordpress plugin, so the Find the URL of the current plugin directory for this example is following below.

Get WordPress plugin directory URI

$plugin_dir_path = dirname(__FILE__);

$plugin_dir_path = plugin_dir_path( __FILE__ );

$plugin_dir_url = plugin_dir_url( __FILE__ );

$plugin_directory = plugin_basename(__FILE__);

get plugin directory url

for the URL

plugin_dir_url( __FILE__ );

for the path

plugin_dir_path( __FILE__ );

WP_PLUGIN_URL – the url of the plugins directory

WP_PLUGIN_DIR – the server path to the plugins directory

$full_path = WP_PLUGIN_URL . ‘/’. str_replace( basename( __FILE__ ), “”, plugin_basename(__FILE__) );

Getting to the Plugin Root with plugin_dir_url()

plugins_url vs plugin_dir_url in WordPress

plugin_dir_url()


e.g – http://www.example.com/wp-content/plugins/foo/

wordpress plugins_url

plugins_url( ‘img/logo.jpg’ , __FILE__ );

will return a url like http://www.your-website.com/wp-content/plugins/foo/img/logo.jpg

How to Get Current Plugin URL in WordPress?

To get the current plugin URL in WordPress, you can use the plugins_url() function. This function retrieves the URL of the current plugin directory, which you can use to access files within that directory.

Here’s an example of how to use plugins_url() to get the current plugin URL:

$plugin_url = plugins_url( '', __FILE__ );

In the example above, the plugins_url() function is called with two parameters. The first parameter is an empty string, which indicates that you want to retrieve the URL of the current plugin directory. The second parameter, __FILE__, is a magic constant that refers to the current file (i.e., the file that contains the code).

After running this code, the variable $plugin_url will contain the URL of the current plugin directory. You can then use this URL to access files within that directory, such as CSS and JavaScript files.

Note that if you want to retrieve the URL of a specific file within the plugin directory, you can add the path to that file as the first parameter of plugins_url(). For example:

$js_url = plugins_url( 'js/my-script.js', __FILE__ );

In this example, $js_url will contain the URL of the my-script.js file within the plugin’s js directory.

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Fetch Current Plugin URL in WordPress.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment