Enqueuing js properly
-
Good evening
I usually don’t have problems with the plugins I develop, but I have actually a doubt related to the proper way to insert javascript (or css) in a plugin.
I have a plugin that when the shortcode is called, loads a pre-existant php file (with html, php and javascript code, etc.) that must by itself call js files (most can be called directly with their url because they are fully customized for that script only) and outputs it to the place of the shortcode. The question is, how to enqueue jquery.js, or moment.js or even a customized one.
If I want to load a js file with wp_enqueue_script(), do I do this directly in the pre-existant php page (that will be outputted by the shortcode routine), or in the plugin file? I made some tests, and I get errors, from jquery or moment problems, to having the libraries loaded at the end of the php code.
What is the proper way to do this? What do I place on the plugin php file, and what do I put in the php custom file called by the shortcode?
Can someone give me a small example?Thanks for the help.
Best regards
JKepler
- The topic ‘Enqueuing js properly’ is closed to new replies.