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]
- Retrieve POST data from AJAX call
- 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
- problem with ajax and the path to the php page
- How to use wp_localize_script in a WordPress page other than functions.php?
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to stop loading multiple copies of jquery
- Update WordPress Custom Field with AJAX on cached page
- Targeting single page with JS
- JS completely stopped loading but Files are found
- Click loads template via ajax
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- Loading jQuery in the footer after removing jQuery migrate?
- Returning a value from a PHP page
- Sending jsPDF documents to the server
- 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
- js file in root loading without
- WooCommerce – Reset quantity input field when variation changes
- 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”
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- How to design a table based on css values set from admin/dashboard
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Adding Custom Slider
- Save Search System
- dynamic dependent select dropdown
- Are nonces in WP REST API optional by default?
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- Ajax load more button for comments wordpress
- Slick + PHP + ACF + JQuery slide reveal not working
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Fancybox type popup window that’s not an iframe
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- How do I Import / Upload Files with jQuery AJAX?
- Why does wp_head hook my functions to the beginning of my source code?
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- What are the advantages/disadvantages of using jQuery DOM manipulation as opposed to PHP DOM manipulation?
- Is it save to use eval for a jQuery callback method coming from the database?
- Function won’t run onclick using Ajax
- WordPress plugin admin page – using WordPress function in linked php file
- A $_POST should occur when submit form but is not?
- Extract links from content
- with PHP within splits the link
- Cloning add_settings_field() with jQuery
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How to load previous or next attachment with jquery ?
- Execute PHP code only with specific user role
- How to set value selected using select2 jquery plugin
- Customizer control save then return to default
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- Failed to load resource: the server responded with a status of 500 (Internal Server Error) through wp_admin_ajax.php
- Log out without confirmation request (nonce)
- Ajax filter with loadmore button
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- Update $wpdb query with AJAX
- AJAX to add to cart multiple products woocommerce
- WordPress ajax filter returning all posts when it should be filtering by category
- Remove specific javascript when viewing page in Customizer?
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- WordPress load javascript file if something… (after the page is loaded)
- Let user select the number of posts shown per page jquery error
- ACF + WP + Slick Slider Repeater Slide Group PHP not Displaying [closed]
- I was wondering if it’s possible to implement card.js on WordPress
- Wrapping shortcode content in a span or link
- AJAX Filter WHILE Loop not working WordPress
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- WordPress AJAX load post metadata in modal
- Form not working as it should in WordPress, but in a normal HTML site it does
- Why I’m Not Having Access to “$_POST” Data Outside My AJAX Callback?
- problem with category menu, it doesn’t want to show link
- How can I correctly POST to a WordPress page?
- Adding instant search to wordpress page
- Fatal error: Call to a member function get_results() on a non-object in on line 26
- How to link a word comprised of a custom field with another?
- What is the best way to get the first few post from WordPress in different divs using a loop?
- reorder a WP_Query, using a dropdown
- Edit Image/Image Details – Replace button missing
- Use ajax response in PHP function
- JSON Object Value Show Undefine
- Adding jquery using php function
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- Different behaviour between “include_once” and directly echoing out html code?
- notify users when changed database
- How to use js variable to php in wordpress functions.php
- Remove content links (internal and external), but exclude post at specific categories