V
V
Vladislav2020-05-08 17:33:38
WordPress
Vladislav, 2020-05-08 17:33:38

How to make a custom WordPress 404 page?

Good evening.

I want to add the ability to select a 404 page to the customizer.
That is, 404.php is displayed by default, but add a select to get all pages in the customizer, if you select one of them, it will be displayed as a 404 page.

How to implement this?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2020-05-08
@Vladddosss

add_action( 'template_redirect', 'redirect_404' );

    function redirect_404(){

     $page_id = get_theme_mod( 'my_404' )
       if(is_404()):
            wp_safe_redirect( get_the_permalink($page_id));
            exit;
        endif;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question