1. Home
  2. Docs
  3. Developer Documentations
  4. How to register plugin js file

How to register plugin js file

If javascript is used in a plugin, the javascript file is located in the js folder in the plugin directory. For example, if your plugin name is ‘test’, your js file will be located in this directory – plugins/test/js/

All the js files in a particular plugin must be registered for it to have effect on the plugin. The file that register the js file is ‘loader.php’ located inside the plugin.

If for example the plugin name is ‘test’, to register a js file for test plugin, go to ‘loader.php’ in the test plugin directory and enter the following code (assuming the js filename is ‘test.js’):

register_asset("test::js/test.js");

The test:: is the name of the plugin in which the js folder is located.
The js/ is the js folder
The test.js is the js filename.

Thank you for reading.

Was this article helpful to you? Yes No

How can we help?