Using wp_die for error messages

While developing a plugin, we might have to display error messages if something went terrible wrong and the user just can go on, like if their version of PHP is too old.

One way to do it is with die('error'), which kills the page and displays the error message. However, this doesn’t look very pretty and no HTML is printed. Just an empty document with the text ‘error’.

Instead, we could use WordPress build-in function wp_die(), which creates a better looking error message, in which we can provide helpful links etc.

Code Snippet:

<?php wp_die( __("Your PHP version isn't up-to-date, please <a href='http://php.net'>update</a>.") ); ?>

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!