You could try the WordPress function status_header()
to add the HTTP/1.1 404 Not Found
header;
So your Code 2 example would be:
function rr_404_my_event() {
global $post;
if ( is_singular( 'event' ) && !rr_event_should_be_available( $post->ID ) ) {
global $wp_query;
$wp_query->set_404();
status_header(404);
}
}
add_action( 'wp', 'rr_404_my_event' );
This function is for example used in this part:
function handle_404() {
...cut...
// Guess it's time to 404.
$wp_query->set_404();
status_header( 404 );
nocache_headers();
...cut...
}
from the wp
class in /wp-includes/class-wp.php
.
So try using this modified Code 2 example in addition to your template_include
code.
Related Posts:
- Redirect Restricted Page to 404
- How to prevent automatic redirection of 404 errors and “incorrect” URLs?
- How do I skip wordpress’s 404 handling and redirect all 404 errors for static files to 404.html?
- How do I programmatically generate a 404?
- How do I skip wordpress’s 404 handling?
- 404 redirection and Google’s index [closed]
- Redirect feed to 404 page
- Check if post is in draft or pending review?
- Why specific file directory fails to redirect but its parent folder succeeds?
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- Deny access to a path (give 403 or 404 response)
- Redirect a page id url but not the page slug
- Defining a custom 404 for non-WordPress parts of site
- WordPress Auto-Redirecting on 404
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- How to redirect a wrong search on my wordpress website to the error 404 page?
- WP page 404 error only on mobile
- Force 404 redirect to home?
- How can I redirect users on the new 404 page without plugin?
- How to redirect an old page url to the homepage
- Dynamic 404 page content while still keeping 404 status code?
- Redirect to home if page doesn’t exists [duplicate]
- Redirect to parent page if child does not exist
- How to redirect non existent pages/posts in wordpress using htaccess
- How to Redirect WordPress domain.com/?anyword to 404 Page?
- How do I redirect the browser to 404 page, if no posts are found in home page
- How do i make WordPress return 404 instead of redirecting on misspelled page?
- How to redirect if 404 error in wordpress then redirect 404.php url
- Redirect to /404/
- Page editing in backend redirecting to 404 page not found with url /post.php
- How do I skip wordpress’s 404 handling?
- Subpages return 404 server error
- WordPress subfolders htaccess bypassing the root htaccess RewriteRule
- Why my htacess rewrite return 404?
- How to Redirect Url to homepage?
- Stopping media file redirects
- Forcing header cache control in 404 pages
- redirect to 404 page
- Redirect certain 404 pages to parent page
- php refresh current page?
- How to prevent redirect to ‘About’ after core upgrade?
- How to configure nginx to redirect requests to the uploads directory to the production server?
- Force HTTPS using .htaccess – stuck in redirect loop
- Why does WordPress automatically redirect URLs with the parameter “name=” to a different page?
- Multisite 404 errors and non-www redirecting to home page
- Where does the 404 redirection happen?
- Redirect from https to http or from http to https? [closed]
- URL Redirect and Bulk Actions in wp_list_table
- Redirect too many times htacces switching to https
- Disabling the X-Redirect-By response header
- How to hide that a certain non-WordPress directory exists on the server?
- Disabling HTTPS redirection for migration
- Redirect deleted posts to category archive
- Can WordPress pass through a call to an external API and return the result directly to the client?
- Redirecting old post url to 404 in wordpress using htaccess
- How to redirect subcategories to a page?
- CNAME vs A Record for WWW – with 301 Redirects
- Any action in wordpress redirects me to home page
- jQuery Ajax returning correct Response, but after redirect to 404 Error
- Handle regular expression based redirects without .htaccess
- Adding rewrite rule dynamically for search results redirecting to 404 URL
- !is_admin() condition turns true in admin pages
- How to forward all requests starting with a specific folder name to the same folder
- I used single quote to design HTML of my WordPress blog. Now site redirects to index.php everytime than page.php or single.php
- WordPress index.php seems to perform unwanted redirect 301
- Custom Login Form – Redirect user to login page if not logged in
- Extra Text in URL
- wp_redirect and current_user_can issues
- Redirect /home to home.php
- WP_List_table with form of method=GET redirects to wrong url after submit
- My Cloned WP site keeps redirecting to the old one
- Can’t do 301 Redirect, Why?
- Redirect old query string URLs to new add_rewrite_rule URL
- How can I set up a splash page that is redirected to only one time for the visitor? [closed]
- Is there way to redirect all blog post pages to Home page?
- Temporary Infinite Redirect Loop
- A change in URL slug in database returns 404, how can I do auto-redirect?
- Add new post redirection [closed]
- Blog keeps redirecting to the contact page
- WordPress Pagination – 301 Redirect Issue
- Why do my new WordPress pages redirect to home / staging site?
- How to regenerate RSS feed URL like FeedBurner?
- How to avoid redirect 302 in wordpress to the author pages?
- WordPress Staging site is redirecting to live and lost the child theme
- Mailjet Email Subscription + Redirect w/ Custom Template Fails
- how can i find malware code and remove from wordpress site to stop it redirecting to hackers click view pages
- Display a custom 404 page without a redirect
- Redirect after plugin activation
- change home_url and site_url but don’t redirect to home_url and site_url on load
- WordPress multisite and redirect to subpage
- My WordPress site redirects to port 8082
- Custom, conditional redirect on logout
- International characters in slugs to redirect to
- How to Block WordPress from subdomain?
- WordPress redirect to splash page once a day for the first week
- after logout, get_current_user_id still holds value
- Solution for WordPress URL structure changes and 301 redirects?
- Subdomain add comment redirect to 404 not found page iis server
- How to redirect non-logged in users to wordpress login page and bypass some page IDs?
- How can I redirect the user to the page they were on when they clicked “Lost Password” using “retrieve_password_message” filter