Home Wordpress Ajax is Returning a Fatal Error
Reply: 0

Wordpress Ajax is Returning a Fatal Error

user1548 Published in April 24, 2018, 6:34 am

I am trying to make an AJAX call in a child theme I am playing around with, and I am receiving the following error:

Fatal error: Call to undefined function add_action() in

Basically my ajax call goes to functions.php file and in the functions.php I am requiring once the file (ajax.php) with the PHP logic. If in ajax.php file all i am doing is echoing a string, it works fine, but if I try to use an add_action function, it then returns the Fatal Error.

Here is some code.


   url: 'url to functions.php file',
   data: {'my-ajax': 'something'},
   type: 'POST',
   cache: false,
   success: function(data, status) {
      if(status == "success") {
   error: function(xhr, desc, err) {
      console.log("Details: " + desc + "\nError:" + err);

PHP - functions.php File:

      if($_POST['my-ajax'] != "") {

PHP - ajax.php:

add_action( 'testing_ajax', 'testing_ajax_func' );
function testing_ajax_func(){
  echo "Hey There";

The above code fails, but if I remove everything from the ajax.php file and leave behind the echo, it then works.

What is it with the add_action function that is causing the issue?


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312644 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO