Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'wp_redirect' is not working

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.

like image 599
Rincver Avatar asked Oct 25 '13 10:10

Rincver


People also ask

Why is redirect not working?

A URL may not be redirecting for many reasons: Browser cache – Your browser has cached a previous request. Clear your browser cache to get the latest. Server cache – Your site is being cached with some caching software, and this needs to be updated to include your redirect.

Why is my redirect not working WordPress?

One of the main causes is because you have added the rewrite rules on both the cPanel “Redirects” tool and from your WordPress plugin. You can determine this by viewing your . htaccess file and looking if the rewrite rules you created from WordPress appear before the ones you entered using cPanel.

What is Wp_safe_redirect?

Description. Checks whether the $location is using an allowed host, if it has an absolute path. A plugin can therefore set or remove allowed host(s) to or from the list. If the host is not allowed, then the redirect defaults to wp-admin on the siteurl instead.


2 Answers

Just use this as per below:

ob_clean();
$url = get_home_url() . '/login';
wp_redirect($url);
exit();

Or you could use Javascript as well for redirection purpose.

<script>window.location='http://www.google.com'</script>
like image 111
Bhautik Nada Avatar answered Sep 23 '22 10:09

Bhautik Nada


Use the follwing code:-

function app_output_buffer() {
    ob_start();
} // soi_output_buffer
add_action('init', 'app_output_buffer');

Or add ob_start() as first line of your own function which hook into 'init'

Don't forget to add

exit();

immediately after your call to

wp_redirect($url);

link:

https://tommcfarlin.com/wp_redirect-headers-already-sent/

like image 28
Pratyush Deb Avatar answered Sep 23 '22 10:09

Pratyush Deb