web designing

How to avoid “Header already sent issue”?

How to avoid “Header already sent issue” on WordPress plugin or Themes.

It’s been a long time I was fighting with the “Header already sent” issue with our custom WordPress plugin which redirects the users after login to a custom URL i.e. http://rndexperts.com. The plugin was always trowing an error. After making all the changes as per the WordPress recommendations the problem was still there. After some searches and r&d we have found a full proof solution.

By adopting this solution the problem will never occur and you can write your redirect code anywhere without bothering about the “Header already sent issue” or any other buffer issue. You to paste the following code inside your Theme’s function.php or in your main plugin’s file if you are developing a custom plugin.

add_action(‘init’, ‘do_output_buffer’);
function do_output_buffer() {
ob_start();
}

Believe me it’s a great solution. Now you don’t have to deactivate your all the plugin and themes or deleting files from your server. These all are very traditional and sometimes doesn’t work. Being a Plugin developers we know, these all measure never works. Because we know the origin of the error and we also know that we can’t delete our entire work to resolve the issue.

The process of the code is very simple. This code will simply clear the buffer on initialization.

Please write your reviews and comments to help us improving the answer. You can also send us a message to know more.

RND Experts will always be happy to assist you.

Happy Coding!

Leave a Reply

Your email address will not be published. Required fields are marked *