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.

Usually I hook all my custom plugins code with the template_redirect hook but one of the issue I encountered is it does not work for the ajax call.

So if I want to target both standard calls and ajax call what hook should I use?

Is wp_loaded a good choice?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

For AJAX you need to hook into the wp_ajax_{action} hook

Specifically,

add_action('wp_ajax_my_action', 'my_action_callback');
add_action('wp_ajax_nopriv_my_action', 'my_action_callback');

See http://codex.wordpress.org/AJAX_in_Plugins

share|improve this answer
    
Sorry, maybe I asked the wrong question, I mean what hook should I use if I want both standard page request and ajax request will invoke my code. –  Yoga Dec 22 '12 at 14:17
    
sorry but I don't understand what you want to do –  Mark Kaplun Dec 22 '12 at 16:12
    
I want a way to hook so both normal and ajax request will be called. I am not sure if wp_loaded is the safest bet. (I assume template_redirect is the safest bet for normal page request but not for ajax) –  Yoga Dec 24 '12 at 9:58
    
if your question is whether wp_loaded is done every time wordpress is loaded including ajax, then the answer is yes –  Mark Kaplun Dec 25 '12 at 12:28

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.