Cannot get redirect working

none of those conditionals will work at after_theme_setup. Look at the Action Reference page in Codex for the order actions are executed in a request. Try hooking template_redirect instead.

Passing User Messages to Another Page

A standard approach is to add a query parameter to the location header (redirect), for example: $redirect = add_query_arg( ‘my-form’, ‘success’, $redirect ); wp_redirect( $redirect ); exit; Then on the redirected-to page, you can conditionally display a message: <?php if ( filter_input( INPUT_GET, ‘my-form’ ) === ‘success’ ) : ?> Congrats! <?php endif ?>

Need help to repair a 301 redirect problem

I know that this is an ancient thread but I ran across it searching for the exact solution in March 2017. I hope this solution is the trial fix that works for someone and saves a little sanity. I posted it in the X Theme support forum since I had been asking for help there, … Read more

Redirect on successful login

According to the Codex page for wp_redirect(), you should follow your wp_redirect() calls with exit. add_action( ‘wp_login’, ‘redirect_on_login’ ); // hook failed login function redirect_on_login() { $referrer = $_SERVER[‘HTTP_REFERER’]; $homepage = get_option(‘siteurl’); if (strstr($referrer, ‘incorrect’)) { wp_redirect( $homepage ); exit; } elseif (strstr($referrer, ’empty’)) { wp_redirect( $homepage ); exit; } else { wp_redirect( $referrer ); … Read more

How to 301 private posts rather than 404?

Sorry guys, I found my answer: add_action(‘wp’,’redirect_stuffs’, 0); function redirect_stuffs(){ global $wpdb; if ($wpdb->last_result[0]->post_status == “private” && !is_admin() ): wp_redirect( home_url(), 301 ); exit(); endif; } Posts/Pages are removed from the sitemaps, but the page still shows up on the site so that it can get 301’d.

Where does wp_redirect need to be placed to make it work?

Once you’re in the template it’s too late, as headers have already been sent. You have to hook earlier in the request to check, like the template redirect hook: add_action( ‘template_redirect’, ‘wpse52455_redirect’ ); function wpse52455_redirect(){ // do your check and call wp_redirect here } Note that this will get called on every request, so you … Read more

wp_redirect not working after submitting form

You can only use wp_redirect before content is sent to the browser. If you were to enable php debugging you’d see a “headers already sent” error due to get_header() on the first line. Rather than process the form in the template, you can hook an earlier action, like wp_loaded, and save some queries to the … Read more