Aller au contenu
FR

Redirecting 404 Pages

Redirection des pages 404
Version audio de cet article

Redirecting 404 pages: There are many ways and reasons to redirect your 404 pages. With this tutorial, we will redirect 404 pages to the homepage with the template_redirect hook.

Redirecting your 404 pages

add_action('template_redirect', 'themespress_redirect_404_to_homepage', 999);
function themespress_redirect_404_to_homepage(){
    if(!is_404())
    return;
    wp_redirect(home_url());
    exit;
}

This function will ensure that all 404 oages will be redirected and in this case a 404.php template is not necessary in your theme.