Where are you calling add_action()? If it’s in a place where you’re already outputting HTML, it’s too late, and that’s probably a place that wont even be looked at during an AJAX request.
You should include that code in your theme’s functions.php file, or as early as possible in a plugin.
Related Posts:
- WordPress Ajax Problems
- Why function called by admin-ajax executes synchronously?
- Using Ajax with a Class file
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Are ‘wp_ajax’ and ‘wp_ajax_nopriv’ exclusive to authenticated and non-authenticated users?
- Admin Notification after save_post, when ajax saving in gutenberg
- Detecting post type within init action
- How to modify wp_ajax function?
- wp_ajax_[service] returning 0
- Is there a hook that fires before an ajax call?
- Ajax Request not coming back to class
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Conditional action hooks
- Is there a hook to process a backbone restful PUT request inside wordpress?
- add_action and Ajax
- Can I fire an add_action hook inside of a function that recieves data via wp_ajax?
- Placement of add_action() for ajax callback?
- admin-ajax.php ” Missing argument 2″ warning
- Code run fast on a cronjob but slow with a do_action or ajax call
- Which allowed API hooks work to add wp_ajax action?
- Issue understanding and using WordPress filters and actions
- WordPress ajax-action how to return content
- Using admin-ajax prevents regular php form submission
- WordPress action – Pass arguments into action in an AJAX call?
- ajax problem – function on server is not called
- why does not work ajax that add_action registered in wordpress
- wp_ajax action is not run when ajax trigger
- Which hook to use when adding ajax to viewer-facing side?
- Sharing variables in both actions wp_footer and wp_ajax
- change wordpress pagination url after doing the request
- Ajax callback not work
- admin-ajax.php calls fail if referrer is sent with 500
- Refresh Gutenberg with JS for it show updated post
- Set cors header for ajax requests
- Is there a hook that fires after an ajax call?
- How to run an ajax call in elementor editor
- do_action won’t work in ajax callback
- Content including hooks inside wp-settings.php are being called twice in WordPress
- Hook after all metadata are set is triggering several time
- Ajax call works for logged in users and returns “Bad Request” for guests [duplicate]
- Its possible to ajax update the content of the admin custom post type list
- Trigger action via button
- remove_action – pre_get_posts – does not restore original query
- Call public static method from ajax ‘wpcf7_mail_sent’ hook
- Trying to send AJAX data to WordPress hook
- where does my function output from load-* go?
- Static var overwritten with WP AJAX action, works fine without AJAX
- WordPress blocking polling request when signed into Admin
- At what stage does wp_ajax hooks gets applied during WordPress request?
- JavaScript implementation of Gzip
- WordPress AJAX with Axios
- WordPress Nonce Issue for Ajax Login and Logout
- How can I hook into existing WordPress Bulk actions?
- add_action on inherit post status
- Vue.js + AJAX Shortcode
- Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)
- wp_remote_get() to get AJAX url /wp-admin/admin-ajax.php
- How to get post ID in post_updated action hook?
- Hooking into the init action will fire it too frequently?
- My ajax code not returning ajax value
- register ajax calls hook
- Show Post Content with AJAX
- Calling plugin function inside custom plugin for onclick event
- update_post_meta using ajax
- How to export custom database data to excel file
- Divs appearing everywhere in post content
- Custom Login with Ajax not working with IE
- 400 Bad Request when sending XHR from React.js to admin-ajax.php
- How to run a function after wp() in the wp-blog-header.php file?
- Front end theme options ajax returns 0
- Remove tags without a specific meta key from “choose from the most used tags”
- Using get_theme_mod in php ajax form doesn’t work
- add_action in the loop hooks
- Use AJAX in a WordPress Plugin to Get Data From Custom Database?
- Custom RPC end-point security best pratice?
- AJAX – SHORTINIT set to TRUE returns blank
- Ajax mousedown call getting “cancelled” when clicking link
- Get uploaded attachment width & height and attachment ID after upload them
- Refresh checkout fields on add to cart with order bump
- Add Server Side validation in Ajax mail form
- Is it good practice to use REST API in wp-admin plugin page? [closed]
- Struggling with plugin dev basics: add_action
- RTrouble passing arguments to action
- Ajax not sending the data correctly- Multidimensional array
- Passing function into add_action always returns the first argument
- How to check Ajax request only when i opened the Notifications list?
- All WordPress AJAX calls always return 0
- wp_ajax add_action fuction won’t fire on custom jQuery action
- how to get password from user instead wp-generate-password
- Class called in template, AJAX not registering
- Same query in category.php and in function.php, but different result
- How to use nonces for frontend AJAX voting if the page gets cached?
- Objects and get_post_meta() gives me 1 string for latitude and longitude
- WordPress ajax requst returns zero
- wp_editor() in content that was loaded with ajax [duplicate]
- Send button using own contact form [closed]
- How to get data with Select AJAX PHP
- Use add_action to run a script, but only on the post editor page
- Add “load more” functionality to an AJAX response
- weird Internal Server Error – no error log produced