I have a sign out on my site to log out of Wordpress
When logged out I would like to redirect uses to a different URL.
I'm using this in the functions.php
add_action(' wp_logout ',' auto_redirect_external_after_logout ');
function auto_redirect_external_after_logout(){
wp_redirect( ' http://redirect-url ' );
exit();
}
and this in the header
<li class="signOut"><?php wp_logout(); ?></li>
When I run this I get a long list of errors in the page
Warning: Cannot modify header information - headers already sent by
That is the offending code, you are calling the
wp_logout
function that will log the user out and to do that WordPress needs to send the info (headers) to the browser and hence the error.So the final action code should look like
and the logout link should be changed to
If you want to use that hook, you're going to need to use JavaScript, since headers have already been sent:
Alternatively, a more elegant way is to use the wp_logout_url() function in place of your current logout link, and scrap the hook all together. Usage: