0

I'm trying to load a simple jQuery script into a WP footer (using an Avada child theme). I've done it before, but nothing's happening. Can anyone spot my error?

In functions.php:

add_action( 'wp_enqueue_scripts', 'wpalert' ); 
function wpalert() {
wp_register_script('wpalert', '--hardcoded root--', array ( 'jquery' ), null, true);
wp_enqueue_script('wpalert');
}

In my .js file:

$(document).ready(function(){
  alert("test");
})
4
  • Possible duplicate of how to properly enqueue styles and scripts in PHP/WordPress Commented Jan 12, 2018 at 14:46
  • What does html says? Do you see your script there? When does its loading? What error you getting in your 'js' file... so many questions. Commented Jan 12, 2018 at 15:08
  • Browsers have debug consoles. Commented Jan 12, 2018 at 15:10
  • Code turned out to be fine actually - needed to put a jquery link in Avada child theme's header.php file. I'd read that WP included jquery automatically, but apparently not. Commented Jan 12, 2018 at 16:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.