I want to use Register Shutdown Function to track Fatal Errors, my question is, where's the best place to call this so it hits both WordPress, Plugin, and Theme Fatal Errors?


WordPress core register a shutdown function on its own (source) the function shutdown_action_hook registered to be ran on shutdown, call

do_action( 'shutdown' );

and little more (source).

So, if you want to register a shutdown function in WordPress way just add your function on 'shutdown' hook:

add_action( 'shutdown', 'my_shutdown_callback' );

function my_shutdown_callback() {

Where to put this code is not very important, a plugin, a mu plugin, functions.php, it doesn't matter, it will run always on shutdown...

Of course register it as soon as possible allows you to catch early errors, so using a mu plugin you can catch errors that happen on plugins init.

  • I mean, are there really any other alternatives to putting it at the top of my themes functions.php file so that it registers as early as possible? +1 – Howdy_McGee Aug 1 '14 at 21:32
  • @Howdy_McGee when developing a theme, no, there is no (useful) alternative. Possible alternatives are are on top of plugins or MU plugins files, but if you are developing a theme... – gmazzap Aug 1 '14 at 21:44
  • The reason that I'm looking to do this is because I do manage multiple themes, and would like to run automatic updates on all of them but the problem with that is if one of the plugins isn't compatible and throws a fit. The only other option I was thinking is to manually add it to wp-config.php or a similar file but I'm not sure what files get overwritten on update. – Howdy_McGee Aug 1 '14 at 21:47
  • 1
    @Howdy_McGee use a plugin, or a mu plugin. In the latter case you can just put the code I posted (of course using the real callback) and save the file in the mu-plugins folder and you are done. If you use a regular plugin than you have to use plugin headers and activate it in backend. – gmazzap Aug 1 '14 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.