One option is to use wp_add_inline_script()
to inline the action url to the page source. This can be done for example on the admin_enqueue_scripts
action.
In the example below I used admin_url()
with wp_nonce_url()
to retrieve the nonce wp-admin url and then added the query paramters to it with add_query_arg()
.
add_action( 'admin_enqueue_scripts', 'my_admin_action_url', 5 );
function my_admin_action_url() {
$actionUrl = add_query_arg([
'action' => 'duplicate_post_clone',
'post' => 30808,
], wp_nonce_url( admin_url('admin.php'), 'action' ));
wp_add_inline_script( 'jquery', "var myAdminActionUrl="{$actionUrl}";" );
}
The url should be now available in your script via the myAdminActionUrl
variable.
Related Posts:
- Do I require the use of nonce?
- Security – Ajax and Nonce use [closed]
- wordpress count link clicks by ip address
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Form Security: nonce vs. jQuery
- Trying to prepend a Hashtag symbol to the_tags links [closed]
- Most efficient way to add javascript file to specific post and/or pages?
- How to correctly add Javascript in functions.php
- Can I use the same nonce for multiple requests on the same page?
- How to use nonce with front end submission form?
- How can I fetch loop of post titles via AJAX?
- Pass media upload value to input field
- Add a class to links in the visual editor (how to get old dialog back)
- Retrieve POST data from AJAX call
- Combine CSS and JS files from plugins
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- Detect a focus on wp_editor
- WordPress “Link has expired” error on updating posts
- WordPress Ajax always returns a 404 error
- Is it possible to get a theme customizer setting from wp.customize using jquery?
- Jquery no more loading, load-scripts.php not found (404)
- Removing jQuery migrate and working with dependencies
- 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
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- Refresh page after update_post_meta
- How to use WordPress (PHP) functions in AngularJS partials files?
- How to stop loading multiple copies of jquery
- Jquery ajax to custom php file: returning blank data
- jQuery functions only work on homepage
- Nice scroll to wordpress
- Update WordPress Custom Field with AJAX on cached page
- I want to remove the links from the term list returned by get_the_term_list
- How do I add a php statement to a jQuery string
- Looking for a better way to handle an ajax script that pulls in post data on click
- Bulk Image upload and one image for each post?
- Targeting single page with JS
- Infinite-Scroll Plugin and Jetpack Infinite Scroll Plugin – Adding to “Thoughts” Theme
- JS completely stopped loading but Files are found
- How can I loop into two different DIVS without repeating the DIVs
- Can’t use get_results() in ajax query
- Remove commas from WooCommerce checkout addresses fields
- Using an Image Slider twice on the same page
- Filter link to existing content suggestion
- Problem with WordPress Ajax form
- Click loads template via ajax
- Change links automatically to affiliate links
- 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]
- Passing jQuery value using Ajax to a page template
- When must I use and verify nonce?
- Using wp_localize_script to store the template url into a variable to use in JS
- How to add a dynamic javascript snippet to the footer that requires jQuery
- Check if user is logged in when clicking certain links on certain pages
- What SQL / WordPress queries would need a nonce?
- ajax_object is not defined when ajax calls the function
- How to speed up admin-ajax.php in wordpress
- Loading jQuery in the footer after removing jQuery migrate?
- JQuery not working on WordPress Admin page [closed]
- Returning a value from a PHP page
- Why is this Ajax not working?
- Stumped – Ajax Response Returns 0
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Asking popup for delete post in WordPress [closed]
- Sending jsPDF documents to the server
- Use ajax from function.php
- Ajax return code 400
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Shortcode return function with link href inside PHP
- Parsing php string in jquery [closed]
- How to properly insert a link to a template in WordPress?
- doing an ajax request always outputs 0
- jQuery .each to get post meta and subtract from a sum
- Show post in slider
- How do i use this jquery script on a wordpress site?
- Using shipped version of jquery
- How to show a dynamic_sidebar if main content content’s height is > a set amount?
- How to test nonce with AJAX – Plugin development
- Woocommerce add to cart quantity buttons with AJAX
- js file in root loading without
- hover image appears below placeholder instead of overlayed
- combine Code 1 with Code 2
- WooCommerce – Reset quantity input field when variation changes
- WP nonce invalid
- class click counter save number
- Slider loading issue
- Taxonomy linked to pages
- Checking for new message using AJAX and PHP. Server overload?
- jQuery not defined
- AJAX request status 200 but no actual “response”
- Conditional Header in wordpress
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to select the contents in the text view textrea in wp_editor?
- Proper syntax or method for keeping url in modified isotope / category links
- ajax, right way to do it and make it works?
- Is there a way to programmatically create multiple pages utilizing the same template but different content from a json file?