You can use the constant DOING_AJAX to check if a current request is AJAX or not. This would let you do something like this in your templates:
if ( DOING_AJAX ) {
//show your content
} else {
//return 404 error
global $wp_query;
$wp_query->set_404();
}
Related Posts:
- Confused on AJAX submit form through page template
- use jQuery.load() to include a php file in a div, wp_query() is part of php file
- Is it possible to determine whether a page is a page template by page_id in ajax call?
- AJAX Post from same domain to a wordpress page
- retrieving page content per AJAX [duplicate]
- ajax page template
- Access-Control-Allow-Origin error sending a jQuery Post to Google API’s
- Show spinner GIF during an $http request in AngularJS?
- ASP.NET MVC controller actions that return JSON or partial html
- How to check if I am in admin-ajax.php?
- gettext does not translate when called in ajax
- Execute one AJAX request after another AJAX request finished
- Ajax and autocomplete
- Load tinyMCE / wp_editor() via AJAX [duplicate]
- Saving (Updating) Post / Page Edits With AJAX
- Is there a hook that fires before an ajax call?
- AJAX request from Chrome Extension to WordPress Website
- Minimal WordPress load for only `get_option` to work (because ajax…)
- Why is admin ajax reloading my page
- Plupload in metabox – AJAX action not working in Class
- Admin Ajax always return 0 on form submit
- Why this plugin doesn’t work with media upload page?
- Ajax call in wordpress not working for subscriber user in front site
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Solve cors problem using rest api or ajax
- Extending wp JavaScript base class to make a post request to a custom REST endpoint
- Why does WordPress Heartbeat login not refresh the nonces?
- wp_localize_script escaping my url – fix or alternative
- Insert wp_editor on front-end with AJAX?
- Buddypress: Load Ajax Without Template Pack [closed]
- Woocommerce Ajax Add cart not working
- I have to post data by AJAX in wordpress to another Website
- Placement of add_action() for ajax callback?
- WordPress ajax problem need wordpress expert?
- Identical wp_rest nonce returned from rest_api
- wp_ajax function did not call
- wp_handle_upload returns empty error array
- Enqueue script in plugin is not working
- Single page site + pushState?
- Interim-Login form on frontend
- Ajax call does not work for this simple code
- Save value from Javascript object to WP user
- wp_update_post onclick button using ajax
- add Additional class to woocommerce cart-contents link
- Ajax insert or update data
- Check ajax triggered from front-end or from dashboard
- Add Ajax to rating button
- Why, if a function accepts arguments, it fails on ajax calls?
- wp_ajax declaration confusing for Front end
- Delete ACF repeater field row on Front End
- No errors in the console but Ajax call doesn’t seem to be working
- Preprocess submitted data
- Update status, meta while inside a post using AJAX button
- How to disable drag-and-drop upload function in Media Library?
- Can’t retrieve any content from Ajax-loaded page
- adding ajax load more to display images from meta box
- ajax in admin menu
- admin-ajax.php not loading anymore
- How to load dynamic option with ajax
- How do you use do_shortcode via AJAX call?
- Auto-suggest to display meta-data, but not to include it upon click
- Register Template
- Why is the file not uploading to the server?
- Get localize of a loaded javascript
- is there’s a way to get the next page content generated by page break block with ajax call?
- REST public POST giving 403 forbidden nginx
- Query data after an Ajax insert
- How to get next and previous post into ajax formed modal windows?
- Passing value from select form with Ajax not working
- Sending email through Ajax without page refresh hangs on admin_ajax.php
- Is there a public ajax endpoint?
- Why Ajax Doesn’t Work?
- How can i do public ajax call?
- How to prevent multiple post with same meta value being created simultaneously in WordPress (with ajax)
- Content including hooks inside wp-settings.php are being called twice in WordPress
- Problem when sending file via ajax
- wp_verify_nonce not working on the mobile device
- Frontend AJAX Media Upload returning 404
- 404 error custom post type rest api
- How to update cart total after AJAX success
- Change button text after ajax db update
- How to implement AJAX within a class storing shortcode atts as class variables
- How do I display posts of a specific day?
- (Frontend AJAX) get post data WITH image thumbnail?
- Native WordPress Video Shortcode Not Working After Post is Loaded via Ajax
- Ajax Function call is always returning 0 in front end(without plugin) [closed]
- Ajax live search, “No products found” when the title contains apostrophes and quotations
- Add Ajax loaded posts to existing posts
- Speeding up admin-ajax.php
- admin ajax is not working for non logged in users
- Change search to outpout category name instead of Post type name
- ‘Dehighlighting’ navigation once clicked
- wp_localize_script not create variable in head section
- AJAX admin Internal 500 error Failed to Upload
- Class property not visible inside ajax callback function?
- Translating wordpress foreach to ajax
- AJAX loading with custom parameters
- Adding custom fields to Wired Impact Volunteer Management Plugin
- Placing ajax actions in different class
- randomly get 400 error while user is logged in wp_ajax