There is an HTML form input. Here’s the code:
<?php if(isset($_POST['login'])) {
wp_redirect("/");
}
<form accept-charset="UTF-8" method="post" >
...
<center><input name="login" type="submit" value="вÑ
од" />
</form>
But redirect doesn’t work. Install debug plugin redirects to wp, that’s what it showed.
http://i.stack.imgur.com/Im4eE.png
PS:
<?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>
It does not work either.
Use the follwing code:-
Or add
ob_start() as first line of your own function which hook into ‘init’
Don’t forget to add
immediately after your call to
link:
https://tommcfarlin.com/wp_redirect-headers-already-sent/
I think your code doesn’t begin with that
if
condition!wp_redirect
will send an header, so printing/echoing something before it, will have result in failure.So check and see if before this:
there is no character out put. Also do not forget to put
exit;
right afterwp_redirect
.Just use this as per below:
Or you could use Javascript as well for redirection purpose.
Make sure you don’t have:
get_header();
or any wordpress function that potentially creates contents like header and footer in your template. Otherwise the redirection won’t work.Some developers try to clear the page by using
ob_start();
but if you have content in your page even if you useob_start();
the redirection won’t work.and then simply try this code:
Try the following, which also forces on error reporting:
From PHP header redirect not working
Edit:
Since it’s giving you the
headers already sent
warning, try adding the following at the very beginning of your code:ob_start();
From Warning: Cannot modify header information – headers already sent..
I faced same problem and none of these solutions worked for me.
The only thing that I noticed is different at the page is that I used
wp_redirect
belowget_header()
and it will work fine if you used it above it.