• Resolved Jan

    (@krugmedien)


    Hi,

    when a plugin or theme causes a fatal error, WordPress shows the message “there has been a critical error on your website”.

    Is it possible to redirect users to a custom error page in this case?

    Something like this:

    if ( is_critical_error() )
    {
        wp_redirect( "https://mywebsite.com/critical.html" );
        exit;
    }

    Thanks. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, this is possible.
    Create a php file named “php-error.php” in your wp-content folder.
    In this file just add your redirect

    Thread Starter Jan

    (@krugmedien)

    @benniledl thank you very much, that works!

    If anyone is interested, the php-error.php file is loaded from \wp-includes\class-wp-fatal-error-handler.php

    if ( defined( 'WP_CONTENT_DIR' ) ) {
      // Load custom PHP error template, if present.
      $php_error_pluggable = WP_CONTENT_DIR . '/php-error.php';
      if ( is_readable( $php_error_pluggable ) ) {
        require_once $php_error_pluggable;
    
        return;
      }
    }

    By default you can add a 404.php file to your theme.
    If you add this code to the php-error.php file, you can also include a 500.php in your theme:

    <?php 
    $file = get_stylesheet_directory() . '/500.php'; 
    if ( file_exists( $file ) )
    {
      include( $file );
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Redirect to custom page on fatal error’ is closed to new replies.