'Is `exit()` required after running `wp_redirect()` in PHP, and why? [duplicate]
This is a sample hook that is run after a particular form on a Wordpress admin page is submitted, which I found in this StackOverflow answer:
public function foobar_save_admin_action()
{
// Do your stuff here
wp_redirect( $_SERVER['HTTP_REFERER'] );
exit();
}
Is the exit() required after wp_redirect()? What would happen if I didn't write it?
This answer says that you should write exit or die after performing the redirect but it doesn't explain why.
Solution 1:[1]
If you don't have any code under header, you don't have to.
If you have code you definitely should. Otherwise the script execution is not terminated. Setting another header alone is not enough to redirect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abdullah Bozda? |
