Yes, enqueueing is the recommended way to load scripts in WordPress. You can enqueue the script via a custom plugin or via the functions.php file in your theme.
Here is the official documentation on enqueueing scripts in WordPress.
You might also want to check the plugin directory to see if there are already any plugins for adding an iContact form via your site’s admin.
Thread Starter
ejm151
(@ejm151)
Thank you Archetyped. Now I’ll have to figure out how to enqueue the script in the functions.php.
Thread Starter
ejm151
(@ejm151)
Ok, so I’ve enqueued the script. Now for a really dumb question: How do I get it into the body of the page so the signup form displays?
I know this isn’t a WordPress problem but any help would be greatly appreciated.
Thanks,
ejm151
When you enqueue the script, it loads the script during the wp_enqueue_script hook, which means its included on every page already.
You can verify this by checking the resources tab in the developer console of your browser.
Thread Starter
ejm151
(@ejm151)
Yes, the function containing the script is in the <head>. I can’t figure out how to call it so the form appears on the page.
Thread Starter
ejm151
(@ejm151)
OK,I created a js function:
function post_icontact_form() { document.write("<script type='text/javascript' src='//app.icontact.com/icp/loadsignup.php/form.js?c=somenumber&l=somenumber&f=somenumber'></script>");}
and then enqueued it. My problem is that the only way I can think of calling it is to put the following code into the page:
<script> post_icontact_form() </script>
which seems like defeating the purpose of enqueuing.
Any suggestions?
Why not simply enqueue the script file that you’re using post_icontact_form() to load directly?
Thread Starter
ejm151
(@ejm151)
I don’t understand, how will enqueuing the script cause it to load directly and how do I control the form’s placement on the page?
Thank you for your patience.
The JS function you posted adds the <script> block to the document.
Enqueuing the file via WordPress adds the <script> to the document.
They both do the same thing except that you don’t have to call a JS function when you enqueue a file.
Thread Starter
ejm151
(@ejm151)
OK, I understand about enqueuing the JS function script but how do I control where on the page the iContact form appears?
Thanks.