Customize WordPress error styles and content

WordPress one three hundred and eighty-one Reading mode

The wp_die() function is a supplement of WordPress to the PHP die() function. It is used to display HTML error messages. For example, when the author role wants to access the topic page, it will display "Sorry, you can't access this page" and terminate the access.

To customize the style and content of prompts, you can add the following code to the current theme function template functions.php:

 function custom_error_handler( $error ) { echo '<style>'; Echo '/* Write a custom style here */'; echo 'body { background-color: #F5F5F5; }'; echo '.error-message { color: red; }'; echo '</style>'; Echo '<h1>Error</ h1>'; Echo '<p class="error message">Sorry, you have no permission to access this page!</p>'; exit(); } add_action( 'wp_die_handler', 'custom_error_handler' );
 Customize WordPress error styles and content

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
WeChat copied
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
    •  Baa Ticket Movie
      Baa Ticket Movie two

      This is good. It can be customized

     anonymous

    Comment

    Anonymous netizens
     :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

    Drag the slider to complete validation