In your functions.php file you should add an action to enqueue your scripts.
<?php
function my_enqueue_scripts() {
wp_enqueue_script(
'load_post',
get_template_directory_uri() . '/js/load_post.js',
array( 'jquery' ),
'1.0',
1
);
wp_localize_script(
'load_post',
'wp_ajax',
array(
'url' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'ajax_nonce' )
)
);
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
Related Posts:
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- How can I fetch loop of post titles via AJAX?
- Retrieve POST data from AJAX call
- Do I require the use of nonce?
- WordPress Ajax always returns a 404 error
- problem with ajax and the path to the php page
- How to use wp_localize_script in a WordPress page other than functions.php?
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Security – Ajax and Nonce use [closed]
- Jquery ajax to custom php file: returning blank data
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Update WordPress Custom Field with AJAX on cached page
- Looking for a better way to handle an ajax script that pulls in post data on click
- Targeting single page with JS
- Can’t use get_results() in ajax query
- Problem with WordPress Ajax form
- Click loads template via ajax
- Display notification only once
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Checking for new message using AJAX and PHP. Server overload?
- AJAX request status 200 but no actual “response”
- wordpress count link clicks by ip address
- Ajax load more posts with multiple tax query
- WordPress Sending data to Ajax with select option
- WordPress ajax doesn’t display object method on jQuery .change() function
- Ajax loaded form replaces form action with Ajax url
- prevent default not stopping page refresh. Passing form information to and from php with ajax in a wordpress site
- Ajax date_query not working past the first iteration
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- AJAX pagination, update current page
- Save Search System
- adjust section according to country?
- populate form fields in a loop with ajax
- dynamic dependent select dropdown
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- How to add a do_action on refreshing of WP customizer?
- Setting value of session with Ajax not working
- how to make custom ajax handler?
- [jQuery]Adding shortcode
- Display parent and child taxonomies in separate drop down select fields
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- How to disable controls in theme customizer?
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- WordPress admin-ajax.php 400 bad request
- Why does wp_head hook my functions to the beginning of my source code?
- WordPress Ajax Call inserting data but success response false
- Ajax contact form return 0
- AJAX – Returning Two JSON Objects with One PHP Function
- Pull GetOption() variable into jQuery dynamically created html
- Unset session variable on page reload / setup but exclude AJAX
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress Ajax Always returning 0
- Function won’t run onclick using Ajax
- Theme not calling Jquery properly
- How to keep track of when a vote is cast?
- WordPress plugin admin page – using WordPress function in linked php file
- A $_POST should occur when submit form but is not?
- My jQuery Ajax form submit is still refreshing page?
- jQuery Ajax PHP function call returning [object Object]
- Shortcode to pull posts
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- Output votes to div dynamically in wordpress
- Get uploaded image and attach it to the new post
- Admin-ajax php not working on new wordpress version
- Proper way to use WordPress function with AJAX PHP file
- Live search from database table
- Add a counter for mouseovers (custom field)
- Accessing an API with jQuery and AJAX
- Execute Jquery when a specific page in my plugin is loading
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- Load Meta box value into div AJAX [duplicate]
- Jquery autosave text area after typing
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- notify users when changed database
- getJSON response to PHP
- ajax problems on loading page [closed]
- Upload multiple files via ajax from an HTML file input
- Help with AJAX request
- I got this error POST https://localhost/meraboilerwp/[object%20Object] 404 (Not Found)
- custom AJAX filtering logic and outputting results into an Elementor Loop Grid widget
- Help with uploading file with AJAX and PHP
- Help with creating commenting system using PHP, jQuery and AJAX
- Update shortcode values using ajax call
- ajax select parent show child in another select and show posts in another select-ajax filter search
- Add/Remove User Meta Array via AJAX
- How do I ensure that the URL parameters are updated correctly when multiple filters are applied
- Filtered queries not responeding to page path