assuming you are properly adding the AJAX script to your theme via wp_enqueue_script
, you can pass data to the script via wp_localize_script
, which you should already be using to pass the path to admin-ajax.php
if you are using AJAX correctly within your plugin or theme.
see the Codex page on AJAX for more info. this tutorial linked at the bottom of that page has all the examples you’ll need.
a purely javascript solution (which I don’t recommend) would be to use the location object to determine context.
Related Posts:
- which is the function that removes accented vowels?
- Slugs as breadcrumbs for Pages
- Sanitize slug title
- is_account_page() change to page slug
- Identical custom taxonomy slugs for same hierarchical children
- Use /prefix/postname as a slug in post_name?
- Get term slug by term id and then explode it
- How to assign php file(template) to several pages with same prefix page name/slug
- How Can I Create a Friendly Slug for a Dynamic Page?
- Display list of pages that contain a certain string within the slug
- Get child-pages slugs of current page into js-file
- Adding a second email address to a completed order in WooCommerce [closed]
- Advantages and disadvantages of using automatic-feed-links
- How to change the markup WordPress inserts for post images
- Is it possible to override this function/class in a child theme?
- Change meta tags programatically
- Convert hyphen to underscore in permalinks
- Adding extra SVGs to TwentyNineteen child theme using class TwentyNineteen_SVG_Icons
- Use a function to update post meta based on other post meta
- wp_mail not running inside Cron
- Remove product description from product archive page
- Logging in redirects to correct page but shows logged out content until forced refresh
- Adding body class when post contains a specific shortcode
- Displaying Widgets
- Limit posts only on home page – ideally in functions.php
- Make Categories a Dropdown Menu in Media Library
- If is multiple page templates
- Loop (iterate) through Multi-Site sub-sites (blogs)?
- Proper way of using functions in action hook?
- Custom function for specific user role
- Add custom image size not working
- How to properly add function called by action-hooked function to functions.php?
- Get Current User info using wp_localize_script, in functions.php
- How to add new embed handler not supported by oembed?
- How do I add Bootstrap and LESS to my migrated WordPress site?
- Stuck on maintenance mode
- Not sure if enqueuing js scripts properly
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- How to remove style attribute in WordPress RSS output?
- Multiple Loops Meta Data
- Update user meta of author when post content is viewed
- How to stop wordpress from injecting hard-coded style into image attachments with captions
- If ACF field is empty show different value [closed]
- What is the text that appears beside the page titles in the list of pages in the WP admin?
- Two functions with different arguments and add_actions, but identical code
- How to fix get_the_category function returning incorrect slug?
- How to edit the Tags within the image file URLs?
- How i can put $_GET codes in function.php?
- Disabling visual editor on a specific post
- Disable wp_is_mobile()
- Is there a way to direct unregistered user to registration page when click a link?
- Auto log in hook is requiring a page refresh
- Testing for a shortcode using a function. 404 page throwing PHP Notice
- how to get the post ID from wp_insert_post
- How to get post revisions in my custom rest API? [closed]
- Possible to merge these two functions?
- Strip div From Excerpt
- The Capability to choose post/page template
- The_content and Preg_replace in loaded Iframe [closed]
- dynamic site link for future migration in echo do_shortcode()
- Hide tab Buddypress profile for visitors, not logged in users
- Add a mature content warning to first-time visitors
- Show Featured Image in else statement
- Function to check if custom page is used by page?
- How can I remove page titles without removing the link in the navigation bar in twentyeleven?
- Simplest Way to Build Custom Archives Page?
- Filter for replacing the WP_query object for a given category
- Custom user role still showing up after deletion, ideas?
- wordpress built-in Jalali date convertor
- How to Display WooCommerce Product Price in WooCommerce Archive
- WordPress Function Assistance with Loop
- Bizarre Child Menu Issue on WP Site
- Populate acf-field, depending on block name
- get variables data from functions.php to template wordpress (without global variables)
- Add Change role button for list of user in an event
- I am trying to set post terms to a custom taxonomy
- how to increase connection time
- Shortcode to insert default text and change one word throughout it?
- Classic TinyMCE messing up only Contributor’s HTML
- Reference multiple style sheets, clearing styles for permalink page, custom fields for css
- Add schema to Search result page’s body. Tried using is_search
- Drop down list code for sidebar
- Shortcode Initialization in a Custom Theme
- Hide disclaimer from summary excerpts
- Load scripts into an AJAX div
- WordPress Javascript Widget jQuery Dependency Issue
- Open image size links in a page instead of direct image link
- Allow tags and attributes in post and pages content
- Override parent theme function that is not hooked or in the functions.php file
- Function to get thumbnail img source
- Syntax for a function in order to get post’s title in JSON encoded response [closed]
- Comment Function
- WP Custom Comment Callback Not Responding
- Do something when user creates post (that’s pending)
- Add product to cart from functions.php
- How I can show short content with short tag
- WordPress Custom wp mail template return full template
- Comment turned Invisible
- Is it possible to use a post name in a custom post slug?