Ajax response is always 0

You can’t add AJAX calls from public templates.

  1. They have to get added much earlier
  2. The file that passes the call is admin-ajax.php for a reason: Ajax calls must not be hidden outside admin. For e.g. wrapping your call inside ! is_admin() will let it fail.
  3. Template files are not meant to hold actual function definition and such. This is where Plugins, Mu-Plugins or your themes functions.php file come into the game

Leave a Comment