• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Ani's Webdev Blog

A learning diary of website development

  • Home
  • Demo
    • Ajax Contact Form
  • WordPress
  • Front-end
  • Backend

[WordPress] Difference between die() and wp_die()

Modified on: May 15, 2022

WordPress uses PHP as the core language. So die() would be just fine to use. In fact, I have used it several times and did not notice any major bugs. Never wonder what is the real different between them before I tried the wp_die() yesterday.

This is how it is different on the look:

The die() returns a simply blank page
The die() returns a simply blank page
The wp_die() function in WordPress has a nice box with shadow
The wp_die() function in WordPress has a nice box with shadow

So, rather than design of output, what are the differences between these?

Documentation

  • die() = exit() = Output a message and terminate the current script.
  • wp_die() – Kills WordPress execution and displays HTML page with an error message.

When to use wp_die() and die()

This completely based on my experience so please feel free to share yours.

  • die() output is ugly. Not good for user experience. If you want to display the error to front-end users in a better way, should use wp_die() instead.
  • If you want to pass arguments to control behavior, use wp_die(). It has more options than die().
  • Use of wp_die() will allow other plugins / functions to hook into the event sequence.

Filed Under: Backend, Wordpress Tagged With: php

Recent posts

[WordPress] Let’s Make Plugin E01: A Simple View Count Plugin

[WordPress] Create custom post type programmatically

[WordPress] Open Images in Posts into Lightboxes On Clicks (Without Plugins)

Reader Interactions

You are here: Home / Backend / [WordPress] Difference between die() and wp_die()

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Hi! I am a Vietnamese coder living in Oulu, Finland. Currently I am working with PHP, MySQL, HTML, CSS, and JavaScript. This blog is my learning diary, in which I share knowledge from my own experience or research. Hopefully you can find something useful here and don’t hesitate to open a discussion or leave a feedback!

FOLLOW MY BLOG

Thank you for visiting this website! I hope you find something useful here :). Contact me by email: anh@anhkarppinen.com.