Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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. –  afnrf Jun 29 '11 at 8:51

Your Answer

 
discard

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.