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.
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.
Figured it out, though this is the lamest solution ever: I hooked into wp_footer instead of template_redirect. If anyone has a better solution or place to hook in I’d love to hear about it – thanks! EDIT: That wasn’t the fix I thought it was. Turned out I was writing the function poorly, and did … Read more
WordPress stores the domain name of your site in the database (wp_options table among others). If you just copy the site and database the site will redirect to the domain mentioned in the database. Option 1 : Using a php tool You can do a search and replace using a proper tool to replace www.mydomain.com … Read more
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 ?>
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
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
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.
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
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