Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

jasonsweb on "wp_localize_script"

$
0
0

Hi!

I'm trying to get a like script running on my blog.

This is a part of the code, which I placed in my functions.php:

wp_localize_script('like_post', 'ajax_var', array(
	'url' => admin_url('admin-ajax.php'),
	'nonce' => wp_create_nonce('ajax-nonce')
));

But when I run it in debug mode, the following error appears:

wp_localize_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or init hooks.

I've did many searches, but could only find solutions about "wp_enqueue_script", but unfortunately not about "wp_localize_script".

So is there something I'm doing wrong what makes the error appears?

Thanks in advance!


Viewing all articles
Browse latest Browse all 8245

Trending Articles