-1

I have a similar question as this but the solution isn't working like I wanted. So a little background. I have two custom template pages "login.php" and "welcome.php" and then I created two WP pages: Login page using login.php as template and Dashboard page using welcome.php as template page. Hence the structure is "http://example.com/login/" (using login.php as template) and "http://example.com/dashboard/" (using welcome.php as template). After successful login from the Login page, I want to move to the Dashboard using

ob_end_clean();
header("Location: http://example.com/dashboard/");
exit;

I also tried

ob_end_clean();
header("location: welcome.php");
exit;

However, after successful login, the login form on Login page just disappear but I am not directed to the Dashboard page so I can't do the login again as there is no elements showing on the the page. What could be causing this?

Side note: I get this warning

Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/example.com/wp-includes/class.wp-styles.php:237) in /home/xxx/example.com/wp-content/themes/spacious/page-templates/login.php on line 32

It's a warning but I don't know if that is the cause of not getting directed to the Dashboard page. I had ensured there are no spaces in class.wp-styles.php file between the opening and closing php tags.

Johannes
  • 64,305
  • 18
  • 73
  • 130
saintjab
  • 1,626
  • 20
  • 31

1 Answers1

0

The message means that you cannot use this redirection code (header(...)) after you already have some HTML output in the page.

So if your login form leads back to the same page after submission of the form data, put that code at the top of the page, before any HTML is echoed, in an if clause like "if all form elements filled in and submitted properly", then the redirection will work.

Johannes
  • 64,305
  • 18
  • 73
  • 130