On this page
maybe_redirect_404()
Corrects 404 redirects when NOBLOGREDIRECT is defined.
Source
File: wp-includes/ms-functions.php. View all references
function maybe_redirect_404() {
if ( is_main_site() && is_404() && defined( 'NOBLOGREDIRECT' ) ) {
/**
* Filters the redirect URL for 404s on the main site.
*
* The filter is only evaluated if the NOBLOGREDIRECT constant is defined.
*
* @since 3.0.0
*
* @param string $no_blog_redirect The redirect URL defined in NOBLOGREDIRECT.
*/
$destination = apply_filters( 'blog_redirect_404', NOBLOGREDIRECT );
if ( $destination ) {
if ( '%siteurl%' === $destination ) {
$destination = network_home_url();
}
wp_redirect( $destination );
exit;
}
}
}
Hooks
- apply_filters( 'blog_redirect_404',
string $no_blog_redirect ) -
Filters the redirect URL for 404s on the main site.
Related
Uses
| Uses | Description |
|---|---|
| wp_redirect() wp-includes/pluggable.php | Redirects to another page. |
| is_404() wp-includes/query.php | Determines whether the query has resulted in a 404 (returns no results). |
| is_main_site() wp-includes/functions.php | Determines whether a site is the main site of the current network. |
| network_home_url() wp-includes/link-template.php | Retrieves the home URL for the current network. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Changelog
| Version | Description |
|---|---|
| MU (3.0.0) | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/maybe_redirect_404