Tagged: custom 404 page, Error Page 404
Hi Enfold family,
I have a custom function that is located in the functions.php file and it has been designed as redirection after if-else condition. At the same time, I have a Custom Error 404 Page which is defined from the Enfold Theme Options page. But when I try to redirect to the customized 404 page it doesn’t happen. The script basically like that;
if(is_blabla()){
// proceed
}else{
global $wp_query;
$wp_query->set_404();
status_header(404);
get_template_part(404);
exit();
}
Normally, I would expect this code to redirect to my Custom Error 404 Page. Do you have any idea? How can we do this?
Thanks in advance
Hey seferdemirci,
Thank you for your patience, from your snippet above I can’t see if you are using the add_action('template_redirect', '...');
So I tested creating a custom 404 page with the Advanced Layout Builder page and set this in the theme options
then added this function in my child theme functions.php
function is_category_to_custom_404(){
if( is_category() ) {
global $wp_query;
$wp_query->set_404();
}
}
add_action('template_redirect', 'is_category_to_custom_404');
and now when I try to go to a post category I see the custom 404 page, try to see if you can model this for your needs.
Best regards,
Mike