WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a shortcode that contains a form. I want to use jQuery/Ajax for POSTing. For this, I want to add javascript to the page where shortcode is added? Which hook should I use?

  1. wp_enqueue_scripts
  2. wp_print_scripts
  3. wp_print_footer_scripts
share|improve this question
up vote 1 down vote accepted

You want to use wp_enqueue_scripts, but you'll probably first want to:

  1. Loop through the Posts
  2. Grep your shortcode
  3. Enqueue the script, if shortcode is found
  4. Rewind Posts

That way, you only enqueue the script where necessary.

share|improve this answer
bennett Thanks! Would you please also tell what other two hooks do and what is the benefit of using wp_enqueue_scripts over them. – a_fan Jun 29 '11 at 8:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.