[wp-hackers] wp_enqueue_script was called incorrectly...
Otto
otto at ottodestruct.com
Mon Nov 11 18:59:39 UTC 2013
Wrap your call to both of those in a function hooked to wp_enqueue_scripts.
Like this:
function test() {
// your code here
wp_enqueue_script('my_post_like_action', plugins_url().'/js/post-like.js',
array('jquery'), '1.0', true );
wp_localize_script('my_post_like_action', 'ajax_var', array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce')
));
// your code above
}
add_action('wp_enqueue_scripts','test');
-Otto
On Mon, Nov 11, 2013 at 12:53 PM, BenderisGreat
<greglancaster71 at gmail.com>wrote:
> I am trying to enqueue a script, and it's not working out so well for me.
> Here is the code, places after the add_action for the function;
>
> wp_enqueue_script('my_post_like_action', plugins_url().'/js/post-like.js',
> array('jquery'), '1.0', true );
> wp_localize_script('my_post_like_action', 'ajax_var', array(
> 'url' => admin_url('admin-ajax.php'),
> 'nonce' => wp_create_nonce('ajax-nonce')
> ));
>
>
> I am receiving this error:
> Notice: wp_enqueue_script was called incorrectly. Scripts and styles
> should
> not be registered or enqueued until the wp_enqueue_scripts,
> admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging
> in WordPress for more information. (This message was added in version 3.3.)
> in /Users/Jared/Documents/Websites/www.local.dev/wp-includes/functions.php
> on line 3060
>
>
>
> --
> View this message in context:
> http://wordpress-hackers.1065353.n5.nabble.com/wp-enqueue-script-was-called-incorrectly-tp42778.html
> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list