Beginner JQUERY help: "wp_enqueue_script was called incorrectly"
-
Hi all. I’m trying to include and run a simple Javascript file on my site, but am encountering an error. My debug.log file reads:
PHP Notice: wp_enqueue_script was called <strong>incorrectly</strong>. Scripts and styles should not be registered or enqueued until the <code>wp_enqueue_scripts</code>, <code>admin_enqueue_scripts</code>, or <code>login_enqueue_scripts</code> hooks. Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.3.) in /home/artslamm/public_html/wp-includes/functions.php on line 3547
I’m not sure what this means. Can anyone shed some light?
Here are the steps I carried out.
The script consists of one line only:
alert('Hello, World!')
and is in a file ‘test.js,’ which resides in the same directory as my functions.php file.
To add this script to WordPress, I inserted the following code into my functions.php file:
function add_test_script() { wp_enqueue_script( 'test', // name your script so that you can attach other scripts and de-register, etc. get_template_directory_uri() . 'test.js', // this is the location of your script file array('jquery') // this array lists the scripts upon which your script depends ); } add_action( 'wp_enqueue_scripts', 'add_test_script' );
Thanks in advance.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Beginner JQUERY help: "wp_enqueue_script was called incorrectly"’ is closed to new replies.