Ok got it, knew there must be some built-in WP solution to this. Simply call wp_get_referer()
in your callback (for details, see this).
At least it’s working as I need it, let me know if there’s any better solution.
UPDATE
Thanks to @Tom J Nowell, we should also mention that referrers could get stripped for privacy reasons or similar. To thus be on the safe side, there’s no way around passing the referrer’s URL explicitely to the data sent across AJAX, like using document.location.href
.
Related Posts:
- The correct method to pass query vars in AJAX using ajaxurl
- Dynamic URL to reference custom PHP files
- Concatenate site_url and string doesn’t work
- Removing all my hardcoded URLs with get_site_url()
- Encode text string being appended as query to URL [closed]
- Adding “Remember Me” in custom login
- Is it safe to use $_SERVER[‘REQUEST_URI’]?
- Retrieve POST data from AJAX call
- Using wp_send_json to return HTML
- How to check if feed URL was requested?
- WordPress Ajax always returns a 404 error
- urlencoding of the_title() doesn’t work?
- Redirect to Page after Post Submit
- problem with ajax and the path to the php page
- Can i check if user is doing any ajax request?
- How to use wp_localize_script in a WordPress page other than functions.php?
- simple wordpress ajax plugin not working when not logged in
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Update WordPress Custom Field with AJAX on cached page
- Targeting single page with JS
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Constructing a custom login form using ajax
- Click loads template via ajax
- How to retrieve the content (with a specific ID) via ajax by clicking a link tag
- Put CSS inside a PHP file and include it the right way
- Sending jsPDF documents to the server
- Ajax $wpdb not returning table data
- Remove query string specific key value
- How to Fetch values from WP database based on selected option value by onchange using PHP?
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- Checking for new message using AJAX and PHP. Server overload?
- Load a page into a div with Ajax
- Change “add to cart” button color based on Woocommerce product category [closed]
- Ajax request returns ‘Array’. How to output the actual results?
- My php header() function is not working [closed]
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Create custom permalinks to show Custom Post Type’s relationship?
- Fancybox type popup window that’s not an iframe
- Using Select HTML in Bootstrap Popovers
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- WordPress ajax-action failing because of newline in response
- HTML escaping data with ajax requests
- Function won’t run onclick using Ajax
- Changing the color scheme based on the url visited
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- How to return site_url() without https://
- Get related product based on subcategory selected from category id with ID 142
- WP_Query with AJAX returning empty array
- How do i add slugs to a URL, but still redirecting to the same page
- Loading Posts & Category with Ajax
- How to get post category list as select in front-end?
- how to get attached file url for current post?
- Is there a hack for using is_page() within the function.php file?
- How to SELECT number from table and use in calculation . Unsupported operand types
- Submit form to db
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- Can not call .php files after switching to %postname%
- WordPress Conditional / Multiple Taxonomy Query
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- AJAX function running TWICE with WordPress admin-ajax.php
- Tracking Visitor LatLng with WordPress using JS, PHP. How to put data which was extract using JS into DB
- WordPress Search Ajax + Isotope + InfiniteScroll
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- Change ajax live search results
- How to call my PHP function with AJAX ? wp_query
- Can’t pass var from php wp_ajax into ajax script : result undefined or null
- Admin-ajax.php 404 error
- How to pass values from one function to the other using an array variable
- Add Link to PHP message
- get_the_author_meta( ‘ID’ ) just return 1
- Update $wpdb query with AJAX
- custom mailchimp form using HTTP API
- Get WordPress username to customize url
- WordPress is setting from header wrongly in wp_mail
- AJAX to add to cart multiple products woocommerce
- WordPress ajax filter returning all posts when it should be filtering by category
- ajaxurl usage for a custom function
- Need to Echo A Url path to show on a wordpress page
- Prepared DB Query from _POST array
- Pass form attributes to another php template in wordpress
- Custom HTML form using PHP – help with ajax/username validation
- AJAX Returning Way Too Many Posts
- WordPress AJAX load post metadata in modal
- wordpress ajax return 0
- Modify category archive page loop on functions.php
- Run insert if no entry otherwise run update with ajax
- site_url() returns with additional backslashes
- Adding instant search to wordpress page
- Passing multiple variables through url (php)
- AJAX & PHP | Call a specific PHP function from a PHP file via AJAX?
- Load php function with AJAX on modal window
- Cookie not created in AJAX request
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Remove Woocommerce product from cart with ajax/fetch
- WooCommerce Modal Fly cart on add to cart – With AJAX
- Upload multiple files via ajax from an HTML file input
- How to pass javascript var to php var
- Ajax infinite scroll random order shows duplicate posts on custom post type