blog_redirect_404 WordPress Filter Hook
If you ever find yourself in the situation where you have a 404 error on your WordPress site, don't fret! There is a way to redirect those pesky 404 errors to a custom page or URL of your choosing. All you need to do is add a little bit of code to your functions.php file and voila! Here's how it works: First, you need to add the following code to your functions.php file: function my_custom_404_redirect() { global $wp_query; if ( $wp_query->is_404 ) { wp_redirect( 'https://www.example.com/404-redirect/' ); exit; } } add_action( 'template_redirect', 'my_custom_404_redirect' ); Replace "https://www.example.com/404-redirect/" with the URL of the custom page or site you want to redirect your 404 errors to. And that's it! Now, whenever a 404 error occurs on your site, it will be redirected to your custom URL.
apply_filters( 'blog_redirect_404', string $no_blog_redirect ) #
Filters the redirect URL for 404s on the main site.
Description
The filter is only evaluated if the NOBLOGREDIRECT constant is defined.
Parameters
- $no_blog_redirect
(string)The redirect URL defined in NOBLOGREDIRECT.
Source
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |