Article

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 administation) 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 to 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 different, 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!

me.jpeg

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Want more like this?

Keep up-to-date with latest news from Inside the Agency using any of the following services

Advertisement

Digital Ocean

Chris's Reading List

dev-human

dev-human

Things I was unprepared for as a lead developer

I've been a lead developer for 2 years. It has been quite a ride and there were a lot of things I was unprepared for. I've always been a sof... Read more

Moz

Moz

Great SEO Starts with Your Brand

Taking the time to really understand and define your brand allows you to be much more intentional and focused about the way you market your business online. Read more

TechCrunch

TechCrunch

Codie Is A Fast, Rolling Robot Toy That Teaches Kids Progamming Concepts

A robotics company that teaches kids how to code, Codie Labs, took the stage at TechCrunch Disrupt London this afternoon to show off their fast, rolling and.. Read more

KnpUniversity - PHP and Symfony Video Tutorial Screencasts

Fun with Symfony's Console Component

PHP and Symfony Tutorial Screencasts - with free videos, scripts, and code downloads! Read more

JAXenter

Self-promotion is a skill, but is that the skill you're looking for? - JAXenter

Do you want to hire somebody that's good at self-promotion, or are you looking for a certain skill-set? Perhaps you need to shape your job spec differently. Read more

TechCrunch

TechCrunch

When Crowdfunding Fails The Backers Are Left With No Way Out

A few years ago an enterprising programmer dug through Kickstarter's data to figure out how many failed projects there really were. Thanks to a trick in the.. Read more