wordpressplugins

Wordpress: How can I pick plugins directory in my javascript file?


I need to access plugins directory in my customer javascript file. I know we have do have functions to retrieve plugins directory path using php function plugins_url().

However, I need this to retrieve in my js file where I have to put some images.

Any ideas??

PS: My js file is saved as a javascript file and therefore, I can't use php tags in it


Solution

  • Use <?php echo plugins_url(); ?> where you want to get the url in the js file.

    For example:

    var pluginUrl = '<?php echo plugins_url(); ?>' ;