You can’t add AJAX calls from public templates.
- They have to get added much earlier
- 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. - 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