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.


Top ↑

Parameters

$no_blog_redirect

(string)The redirect URL defined in NOBLOGREDIRECT.


Top ↑

Source

File: wp-includes/ms-functions.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More