Menu

Sponsored By: Password Angel - Share passwords, API keys, credentials and more with secure, single-use links.

WordPress wp_redirect() shows a blank page

Over the last few weeks, I have been working on my first WordPress plugin and I am quickly getting to grips with how it all pieces together but I ran into a problem with a rather basic piece of functionality that pretty much rendered the plugin useless until I figured out the issue.

The section I was working on was a form submission (within the WordPress administration) which saved the form values into the database and then redirected the user upon success to another page (using wp_redirect) but this resulted in a blank content pane.

This seems very strange to me as it showed some of the page contents i.e. the header and left navigation but the content pane was completely blank.

I searched around for a few hours trying various suggestions for similar problems, downloading other WordPress plugins and examining how they used the wp_redirect function to see if the authors of these other WordPress plugins had done anything differently, only to find that there was no difference.

I eventually managed to figure out the issue after I read a post regarding a problem another user was having where they were getting a completely blank screen and another member suggested the problem could be due to whitespace which was sent to the browser before the redirect was called resulting in a “headers already sent” problem.

This got me thinking that I did not have output buffering enabled which was strange as I usually have output buffering enabled to resolve this issue, however, in this case, I did not have output buffering turned on and this turned out to be exactly the problem. I added the following line to my .htaccess file and the redirection now works perfectly.

php_flag output_buffering on

I was glad to get this one resolved as I had to spend far too much time on something that I have resolved time and time again. Certainly one I’ll be aware of should there be a next time!

Enjoyed this article?

Thank you for reading this article! If you found the information valuable and enjoyed your time here, consider supporting my work by buying me a coffee. Your contribution helps fuel more content like this. Cheers to shared knowledge and caffeine-fueled inspiration!

Buy me a coffee

Originally published at https://chrisshennan.com/blog/wordpress-wp-redirect-shows-a-blank-page

Subscribe to my newsletter...

... and receive the musings of an aspiring #indiehacker directly to your inbox once a month.

These musings will encompass a range of subjects such as Web Development, DevOps, Startups, Bootstrapping, #buildinpublic, SEO, personal opinions, and experiences.

I won't send you spam and you can unsubscribe at any time.