maybe_redirect_404

The timeline below displays how wordpress function maybe_redirect_404 has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Corrects 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU (3.0.0)
 */
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;
        }
    }
}

WordPress Version: 5.4

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU (3.0.0)
 */
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;
        }
    }
}

WordPress Version: 5.3

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU (3.0.0)
 */
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 ($destination == '%siteurl%') {
                $destination = network_home_url();
            }
            wp_redirect($destination);
            exit;
        }
    }
}

WordPress Version: 4.9

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU (3.0.0)
 */
function maybe_redirect_404()
{
    /**
     * 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.
     */
    if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && $destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT)) {
        if ($destination == '%siteurl%') {
            $destination = network_home_url();
        }
        wp_redirect($destination);
        exit;
    }
}

WordPress Version: 4.6

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU
 */
function maybe_redirect_404()
{
    /**
     * 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.
     */
    if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && $destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT)) {
        if ($destination == '%siteurl%') {
            $destination = network_home_url();
        }
        wp_redirect($destination);
        exit;
    }
}

WordPress Version: 3.8

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU
 */
function maybe_redirect_404()
{
    /**
     * Filter 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.
     */
    if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && $destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT)) {
        if ($destination == '%siteurl%') {
            $destination = network_home_url();
        }
        wp_redirect($destination);
        exit;
    }
}

WordPress Version: 3.7

/**
 * Correct 404 redirects when NOBLOGREDIRECT is defined.
 *
 * @since MU
 */
function maybe_redirect_404()
{
    if (is_main_site() && is_404() && defined('NOBLOGREDIRECT') && $destination = apply_filters('blog_redirect_404', NOBLOGREDIRECT)) {
        if ($destination == '%siteurl%') {
            $destination = network_home_url();
        }
        wp_redirect($destination);
        exit;
    }
}