0

I am using wp_redirect() to redirect to a URL but it gives me the warning below and does not redirect. When should I use wp_redirect()? And does any one know how wp_redirect() works?

**[Fri Feb 28 03:58:36 2014] [error] [client 127.0.0.1] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/virgo/public_html/others/sites/wepay/wp-content/ themes/twentythirteen/header.php:43) in /home/virgo/public_html/o thers/sites/wepay/wp-includes/pluggable.php on line 875, referer: http://127.0.0.1/others/sites/wepay/?page_id=15** 
2

1 Answer 1

1

Headers need to come first therefore you have to place this before any output. This includes error messages. If you run some code that has an issue which generates a notice this will prevent the redirect from running.

Take a look here: http://codex.wordpress.org/Plugin_API/Action_Reference

get_header is the latest point.

I'd suggest doing it once WP has been setup so you can use all conditionals including use of $post but still early. The most appropriate hook in my opinion would be 'wp'.

function wpse_redirect() { if ( ENTER A CONDITIONAL ) { wp_redirect( 'redirect-location' ); exit; } } add_action( 'wp', 'wpse_redirect' ); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.