WhatsApp us

How to Fix WordPress AJAX Not Working Issue (PHP Solutions)

  • Tech Area
  • Last updated on: January 19, 2026


WordPress AJAX is widely used for contact forms, filters, load more buttons, login forms, and dynamic content. However, many developers face the common issue where WordPress AJAX is not working, especially for non-logged-in users.

In this guide, you’ll learn how to fix WordPress AJAX not working issues using PHP, step by step.

Why WordPress AJAX Issues Are So Common

AJAX problems usually occur due to:

1. Missing wp_ajax_nopriv_ hook

2. Incorrect AJAX URL

3. JavaScript errors

4. Missing nonce verification

5. Theme or plugin conflicts

Correct Way to Use AJAX in WordPress

Step 1: Enqueue Script Properly

add_action('wp_enqueue_scripts', function () {
    wp_enqueue_script(
        'custom-ajax',
        get_template_directory_uri() . '/js/custom.js',
        array('jquery'),
        null,
        true
    );

    wp_localize_script('custom-ajax', 'ajax_obj', array(
        'ajax_url' => admin_url('admin-ajax.php'),
        'nonce'    => wp_create_nonce('ajax_nonce')
    ));
});

Step 2: JavaScript AJAX Request

jQuery(document).ready(function ($) {
    $('#btn').on('click', function () {
        $.post(ajax_obj.ajax_url, {
            action: 'my_ajax_action',
            nonce: ajax_obj.nonce
        }, function (response) {
            console.log(response);
        });
    });
});

Step 3: Handle AJAX in PHP

add_action('wp_ajax_my_ajax_action', 'my_ajax_handler');
add_action('wp_ajax_nopriv_my_ajax_action', 'my_ajax_handler');

function my_ajax_handler() {

    check_ajax_referer('ajax_nonce', 'nonce');

    echo 'AJAX Working Successfully!';
    wp_die();
}

✔ Works for logged-in users
✔ Works for guests
✔ Secure

Common AJAX Errors & Fixes

AJAX Works Only for Admin

✔ Missing wp_ajax_nopriv_ hook

400 or 403 Error

✔ Nonce missing or invalid
✔ Check check_ajax_referer()

AJAX URL Not Found

✔ Always use admin_url('admin-ajax.php')

No Response

✔ Use wp_die() at the end
✔ Check browser console

Debug WordPress AJAX Issues

Enable debug mode:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);

Check:

1. Browser Console

2. Network tab

3. debug.log file

Conclusion

Fixing WordPress AJAX not working issues requires correct hooks, proper script loading, and secure PHP handling. Once implemented properly, AJAX improves user experience and website performance.


Subscribe us via Email

Join 20,000+ subscriber

Subscribe on YouTube

PHP Projects
Matrimonial Portal Project in PHP & MySQL Last Updated: December 22, 2025
Event Management System Project in PHP & MySQL Last Updated: December 6, 2025
Online Shopping System Project in PHP MySQL Last Updated: November 26, 2025
Hostel management system project in PHP and MySQL Last Updated: February 14, 2024
Online Pizza Delivery project in PHP Last Updated: February 4, 2024
Parking Management System project in PHP Last Updated: November 5, 2023
Visitors Management System project in PHP Last Updated: August 28, 2023
SNIPE – IT Asset management system v6.1.0 Last Updated: April 21, 2023
Employee Management System project in PHP Last Updated: January 21, 2023