0

I'm looking for the simplest way to redirect a password protected page, to another page after entering the password.

E.g.

<?php if ( is_page('name-of-page') && ! post_password_required() ) { wp_redirect( home_url() ); exit; } ?> 

Using wp_redirect is triggering a 'headers already sent error'.

I've seen some solutions using output buffering to avoid this but, I'm not sure if it is the best solution.

Thanks!

5
  • 1
    You can't call wp_redirect in the middle of a template, it needs to be done before anything else is printed out Commented Feb 12, 2013 at 16:20
  • That's what I understood with the headers error. Is there anything you can recommend? Commented Feb 12, 2013 at 17:41
  • The only non-hackish guaranteed solution is to do it earlier before the page loads. btw how is a user to read the password protected page? It sounds like you're trying to fix a fix, like the "I know an old lady who swallowed a fly" song? Are you trying to implement a membership area? Commented Feb 12, 2013 at 17:43
  • I thought so. No, I'm not trying to implement a membership area. It's just one page, and it's not ideal but it was a request. Commented Feb 12, 2013 at 17:55
  • Thank you for taking the time answer. I really appreciate it. Commented Feb 12, 2013 at 17:55

1 Answer 1

0

Tom J Nowell confirmed what was happening. Inserting wp_redirect in a template causes the page either to partially load or not load at all.

It needed to be placed before the opening <html> to work as it would load everything before </head> then stop.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.