Wrapping it in a function and then adding the following did the trick:
add_action( 'wp_footer', 'my_ajax_script' ); // Write our JS below here
Was all it took
Related Posts:
- ASP.NET MVC controller actions that return JSON or partial html
- How to cache json with wp-super cache
- Why use wp_send_json() over echo json_encode()?
- WordPress function that makes HTML safe to be sent via AJAX request
- WP REST API route request explain
- How to use wp_send_json_error?
- Most performant way of fetching remote API data?
- json encode not work in wordpress
- Unable to parse JSON response from wp_send_json_success [closed]
- Gravity form Load By Ajax Cannot Submit – Error 400
- Ajax store response json in variables
- How do I query posts by a sub value with the API?
- Cache wp-json/posts without a plugin?
- Gravity Forms closes my popup on Validation Error [closed]
- merge wp rest api query to get posts per category does not work
- Retrieve JSON file from JS trough php
- Upload data from weather station to WordPress Website
- Sql formatting for post data within function
- How can I wp_send_json data?
- Full Front End, AJAX comment system and comment reply script
- Send checkbox status with Ajax / JSON and save it
- Chained ajax call, second call returns 0
- Display full WordPress post under search form using AJAX
- Can I use application/json content type in WordPress
- Using wp_send_json_success instead of $result[‘message’], die, etc
- gform_after_submission does not work on ajax enabled form
- AJAX POST Value not being returned – WordPress – AutoTrader API
- Ajax call works for logged in users and returns “Bad Request” for guests [duplicate]
- How to inject data content from external json into a modal, using UIkit?
- how to correctly use json_encode with ajax
- WorddPress website admin part not working correctly – I think ajax/json issue
- 403 error for ajax POST request
- Ajax WordPress pass post URLs
- How to populate data from JSON using AJAX in TypeScript? [closed]
- WordPress Ajax JSON success return no being recognized
- Ajax contact form returnig 0
- Usage of wp_send_json_success and wp_redirect at the same time
- Bad Request 400… jQuery ajax post of json data to wordpress admin-ajax.php
- Using Ajax with a Class file
- SSL breaks customizer: page isn’t returned from ajax
- Stop admin-ajax?
- How to verify nonce from Bulk/Quick Edit in save_post?
- How to implement AJAX post navigation into WordPress?
- wp_ajax_[service] returning 0
- Trying to load content of a post via AJAX
- Insert Post using Ajax
- How can I automatically login using a URL?
- Ajax function returns -1
- Problems with creating sortable sections in customizer
- Is it OK to use a system cron to trigger a function hooked into the AJAX API
- Filter WP user acf field by ajax
- Ajax Request not coming back to class
- How to make ajax content indexable by search engines?
- Ajax requests with different WordPress Address and Site Address setup
- AJAX requests broken due to HTTPS for wp-admin
- query vars in url work but not in ajax call
- is_home doesn’t affect content
- Is it safe to use $_POST directly in my plugin instead of using admin-ajax.php to receive data from ajax?
- How to declare a JS variable in an AJAX call
- is_page() conditional not working inside an AJAX function
- jQuery Ajax passing empty parameters to my function?
- how to send Ajax request in wordpress backend
- admin-ajax.php slow website, how to fix
- ajax nonce verification failing
- admin-ajax.php ” Missing argument 2″ warning
- Update get_pages using ajax on form select change
- Is there builtin way to use protected AJAX endpoint?
- How to create an ajax endpoint without js?
- How to load content from many posts on a page, only if needed
- Making an ajax request from a different domain
- Pagination Using ajax
- wp_ajax_ works fine but wp_ajax_nopriv_ returns HTML and not calling function
- Why is wp_localize_script returning false?
- Change header.php after ajax call
- What’s the latest I can hook into wp_ajax_%?
- WordPress – admin-ajax.php returns 502 Bad Gateway [closed]
- Using admin-ajax prevents regular php form submission
- How to use ajax to get multiple outputs?
- Admin-ajax.php 400 error in custom theme
- Why does check_ajax_referer give a 403 error on https websites?
- WordPress is creating nonce as a logged in user but verifying it incorrectly
- ajax refresh to display new posts
- wp_ajax action is not run when ajax trigger
- Replace link with form to pass variables to javascript / ajax
- Ajax call undefined index
- Is there a hook that fires after an ajax call?
- Dynamic Twitter card images
- How to pass value from ajax to php in no conflict mode?
- What is the relationship between UFW (firewall) being enabled and cron job running?
- Is there a way to add ajax hooks without editing the functions.php file?
- Implement AJAX to fetch pages or posts content in a WordPress custom theme
- about load more ajax
- How to use add_action(‘wp_ajax_[action name]’,…) for a specific page with condition?
- AJAX save options inside class
- register_setting and AJAX?
- ajax response is 0 instead of ‘script’ [duplicate]
- A refreshless WordPress website
- Dynamic dependent select box getting null value
- get_template_part() does not render after the ajax request
- wordpress ajax bad request 400