-
AuthorPosts
-
February 4, 2015 at 5:25 am #390507
If the answer to this is already in the forums, I can’t find it. I’ve already got the .js file registered and enqueued with wp_register_script and wp_enqueue_script as outlined in https://kriesi.at/support/topic/custom-js/. The problem is that when I try to enter code to actually call it, like using onsubmit=”whatever” in my form tag, the call gets stripped out when I save the page.
Also I have a script that’s part of a TransferBigFiles widget that must be called AFTER the widget’s DIV code is rendered, which means it can’t be called in the <head>. What would I do with that one? I figure I could put the script directly into footer.php somewhere, but then I’d have to worry about it getting wiped out every time Enfold is updated. I asked them if they have a WP plugin, but they haven’t responded yet.
I’m sure I’m just missing something that’s right in front of me, so any help would be most appreciated.
Thanks!
Scott
- This topic was modified 9 years, 10 months ago by scotthco.
February 4, 2015 at 6:42 am #390529Hey!
1. I’d suggest binding the event in the JS file instead of the form tag, you can use the following:
http://api.jquery.com/submit/2. You can use the
wp_footer
hook:function custom_func() { // code here } add_action('wp_footer', 'custom_func');
Best regards,
JosueFebruary 20, 2015 at 8:51 pm #399866Must’ve never clicked submit for this reply.
I’m getting the hang of the jQuery binding thing. It’s working quite well, thank you! I did end up using the footer hook for the actual binding calls though. Turns out that wp_register_script and wp_enqueue_script insert my custom script file just before the jQuery libraries, so I couldn’t call jQuery stuff at that point.
One thing I’m still a bit confused on though: Even in the footer where they do work, if I use the $() I get an error that $ is not a function. However if I use jQuery(), it works just fine. Could something else in all the scripts included with the Enfold theme be conflicting with $()???
Thanks again!
February 21, 2015 at 12:29 am #399955Hi,
Wrap your code with like this:
function add_custom_script(){ ?> <script> (function($){ // you can use $ here. })(jQuery); </script> <?php } add_action('wp_footer', 'add_custom_script');
Regards,
Josue -
AuthorPosts
- You must be logged in to reply to this topic.