The proper hook to handle custom 404 content is 404_template
. This happens when WordPress is trying to include the default template, but before any HTTP headers have been sent.
So you can change the template, send or overwrite HTTP headers, and all of that without any checks, because WordPress has done that for you already.
In most cases you should not redirect those requests. A redirect is a 3xx status, not a 4xx.
You might find some inspiration in my old 404 plugin.
Related Posts:
- Filter to change the content of 404 page
- Set a specific page as 404 – not found via my own plugin
- Custom rewrite rule serves content, but returns 404 error code
- Show custom data instead of 404
- If $var is empty, return 404.
- Form submission to another page returning 404 error [duplicate]
- Check current URL is 404 in pre_option_stylesheet filter hook
- Scripts/styles not loading on cloned WP Site when logged in
- What are the advantages to the Settings API?
- How to add Request header in WordPress remote api calls
- Init action hook running late after PayPal’s return url?
- Get specific color from admin color scheme
- wp_remote_get doesn’t work with secure connections https?
- Adding callback function for wp_ajax_ has no effect
- Why are two functions over-riding each other?
- how to set context in WordPress for unit testing
- Should I ask my Twitter plugin users to create their own Twitter App and API Keys to use my plugin?
- WordPress admin deleted user details not removed in database. How to delete WordPress Users from Database
- plugin development: storing language specific options
- Support auto-save and revisions for custom fields
- Gutenberg – What is the best way to save/update post meta?
- Dequeue theme stylesheets but keep widget styling on custom page template
- WP_Query with tax_query, order by most ‘matches’
- Using the Settings API, how should I add multiple values to an option?
- Save Checkbox value in Plugin [duplicate]
- Plugin updates, version dependencies, and backwards compatibility
- Where and how does WordPress store and use its plugin and hook information?
- Cache directory needed for plugin
- How to sanitize user input?
- Remove Internal Style Sheet if no Value Provided?
- edit_{$taxonomy} | Hook
- Worpdress cannot create directory
- Using the default wordpress uploader inside plugin
- WordPress after content Hook & external template part
- Alter post object before display
- get_query_var not works
- Correct check for any admin page with editor
- How to localize admin.php only once
- Failed to Open Stream: Permission Denied While Writing to an XML File in a WordPress Plugin
- Show/Hide ‘add new user’ custom fields in wordpress admin panel by click another field
- “import declarations may only appear at top level of a module” when importing WooCommerce API node module
- How to perform a heavy and long process in cron jobs?
- Woocommerce extend tax report with custom column
- Capture mediaelement events
- Dynamically creating classes for Widget API
- How to query children by post name/slug
- get_the_tags with separator control?
- How to add new options to my WordPress plugin
- Displaying “One Time” Notification in Plugins
- Is it the right way to add jquery and css in wordpress?
- Print Dashboard submenu name and filename
- Are there any security risks when submitting data-attribute data through AJAX?
- My stylesheets are not enqueuing
- Customize existing menu item
- After plugin activation hook
- Dynamically generate meta tags and titles for a wordpress page
- Hook after attachment added and cropped
- Why would you use esc_attr() on internal functions?
- How to get post image root URL?
- Page is loading after submit before the file is processed
- Insert Into Post Not Working For Audio File Using jQuery
- Custom Plugin Options Won’t Update
- Enqueue a file that’s not js or css
- Auto-complete or auto-suggest from stored data in database
- Schedule some work in custom plugin
- What is the replacement for rich_edit_exists()?
- Plugin Development – Multilangual – Different pages
- Passing values between enclosing and enclosed shortcodes
- why does get_option( ‘home’ ) not work while using in plugin [closed]
- How to get changed post title in my custom plug-in which fires when ‘save_post’ is called?
- Rewriting Image URLs from dynamic to original
- Creating open content area and restricted content area
- Javascript Function Called Too Early in PHP Script
- Need Help Determining Where Header Error is Happening
- post content and shortcode content displaying out of order
- How to save page URL as a favorite
- Getting Post ID at “stylesheet” and “template” hooks
- Is there a way to get rendered html content of a WP post after updating?
- How to check category name available or not
- How to store sensitive user data (passwords)
- Quick Draft widget (dashboard.php) using custom post_type
- Generate Static Page to Show Search Results/Detail for API
- How do I use a plugin to swap out the template file for a custom post type?
- Custom Post not Deleting on Uninstall
- User avatar-ACF fields
- How can I specify the plugin language in WordPress?
- Prevent plugin activation and add admin notice
- How to make sure wordpress and woocommerce plugins work on all configurations
- Plugin options with googlemap iframe
- How do I call the dashboard’s sortable javascript in a plugin page?
- Submitting a plugin form to database in admin page
- Only admin should run wordpress plugin shortcode
- How to only Load scripts on variable products page
- Using tag or inline style attribute?
- Forcing the Uninstall Hook to fail
- remove () from category number [closed]
- How to get the value entered in the input field in wordpres
- Sanitize and Save metabox values
- How can I add a custom button to the post editor?
- How to use register_setting()