WordPress wp_redirect() header errors

I wanted to be sure and document this, since it wasted a bunch of my time, and was very frustrating.

I recently built a shortcode for redirecting a parent page to the first child page. In the past, I used a page template. But I wanted to make it into a shortcode so I could include it into a utility plugin pack for my projects.

Strangely, I got the shortcode working until I used it on the next project, which was in a different server environment. Any page that contained the shortcode would spit back the error:

Warning: Cannot modify header information - headers already sent

It seemed at first to be related to the All-in-One SEO Pack plugin. I disabled it, then it came back saying the Hybrid Theme Framework parent theme was conflicting. I wasn’t planning on changing that, so I began looking for another solution.

Apparently some server configurations have trouble with whitespace being in the header info, which causes errors when multiple plugins try to tap into them.

It turns out, you can enabled a PHP feature that solves this issue.

Just add this to your .htaccess file

php_flag output_buffering on

I found the solution here.

I would honestly, much rather find a solution that doesn’t necessitate touching the htaccess file or any other  files. But it will have to do for now.

Mjenn123

This is where you’ll find an amazing bio all about me when I get around to writing one.

Leave a Reply