Skip to content
Advertisement

how to load Javascript in WordPress Plugin

Can someone show me how to include this javascript file into my wordpress plugin. I have tried all the wp_enqeue_script() methods but nothing happens.

ok here is my example plugin code with comments explaining what I would like.

JavaScript

this is the popup.js

JavaScript

So does anybody know how to call this script to work correctly in wordpress plugin?

Advertisement

Answer

You need to specify when the load should happen, try this.

JavaScript

Also, there are errors in your JS, but I have seen the correct version in some answers, hope this helps

Update : There is a hook called wp_enqueue_scripts, as mentioned by @brasofilo which should be used in lieu of init for loading scripts.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement