I used Divi to build the layout for a custom 404 page. I'm using this plugin https://wordpress.org/plugins/redirect-404-error-page-to-homepage-or-custom-page/ to redirect 404 errors to this page. It works, but when I run tools like screaming frog, it returns broken pages as 301 redirects, which I guess is expected.
What I would prefer however is for my 404.php template to include the page I built, so that I can still accurately track my 404 errors. I'm thinking of something like:
#404.php
<?php
require(/*Some function to get my entire custom 404 page by slug or ID*/;)
?>
What I tried:
//Redirect to our custom 404 page
function wf_404(){
//Check if custom 404 page exists to protect against infinite loop
if (is_404() && get_page_by_path('/404-page/', OBJECT)){
wp_safe_redirect(get_site_url() . '/404-page/', 404);
exit;
}
}
add_action('get_header', 'wf_404');
This gives me a general browser 404 error.