0

When a user type inn www.mypage.com/x (which does not exist) the result show an empty body with the header and the footer intact. Most redirect plugins let me redirect one specific URL to another specific URL. What i want is to not only redirect a specific URL, but every non existing URL to a specific URL.

What does this redirecting action called, and how to i do that?

  • Do you mean redirect on 404 not found? – Tom J Nowell Jul 31 at 1:14
2

You can use conditional tag is_404() and wp action hook to redirect whenever the page can not be found.

functions.php

add_action( 'wp', 'se344018_redirect_404' );
function se344018_redirect_404()
{
    if ( is_404() ) {
        wp_redirect( home_url() );
        //
        // wp_redirect( home_url('some/page-slug') );
        exit;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.