The wp_die_handler
filter filters the handler for the function responsible to kill the execution of the script. So it needs to return the callable that WordPress will use when wp_die()
is called.
The actual callable that is returned from the wp_die_handler
filter must output the error message and die.
function wpse_die( $message, $title="", $args = [] ) {
echo 'yolo';
die;
}
function wpse_die_handler(){
return 'wpse_die';
}
add_filter( 'wp_die_handler', 'wpse_die_handler' );
Have a look at _default_wp_die_handler()
for a look at what WordPress outputs from the default handler for wp_die()
.