How Do I Redirect 404 Error to Custom Error Page in WordPress?

When a web page cannot be found, WordPress will return a 404 error. This error can be redirected to a custom error page by adding the following code to your theme’s functions.php file:

// Redirect 404 errors to a custom error page function redirection_404() { global $wpdb; $url = get_permalink($post->ID); $error_page = $wpdb->get_var( “SELECT * FROM wp_error” ); $url = $url . “?error_code=” .

$error_code; $url = $url . “&error_page=” . $error_page; wp_redirect($url, $error_page); } add_action( ‘wp_error’, ‘redirection_404′ );.

This code will use the get_permalink() function to get the post’s ID, and then use that ID to lookup the post’s wp_error table. The code will then use the URL and error_code values from that table to create a new URL that will be used to redirect the user to the custom error page.