Fix for WordPress Plugin Activation Error – “Headers Already Sent”

Sometimes when activating a new WordPress plugin you might see a error like this at the top of your WordPress dashboard.

“The plugin generated 2 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.”

headers already sent
The reason for this error is because there are one or more unwanted characters or white spaces in the WordPress plugin file. WordPress plugin files are written in PHP language and PHP files must begin with the PHP start tag – ‘<?php’ and end with the PHP end tag – ‘?>’. There should be no characters or white-space before the or php and WordPress will through an error. When we check my plugin file for this error there were two white spaces I had unintentionally lest just after the PHP end tag, ‘?>’.

wordpress plugin file

(The 2 white spaces are highlighted) I removed those white spaces and reactivated the plugin and the error was gone.

This is error message I’m used to seeing once in a while while I’m doing WordPress development. It might be either when writing a new custom WordPress plugin or trying to activate someone else’s plugin or even maybe when testing some plugin code I just copied and pasted.

I guess its one of those learning experiences in WordPress and PHP. I’ve been using PHP and developing WordPress themes and plugins for sometime now and still I make this mistake once in while. But once you know why you get an error like this, you know what to do when it happens next time 🙂

Written by: Aksam Zarook
Aksam Zarook is a web designer, developer, online marketer and founder of Zeeron Solutions. With nearly 11 years of work and business experience he excels in web design, web development, graphic design and Internet marketing. He is also a family man with two adorable little kids and rides a motorbike.

Join Discussion Now!

3 comments on “Fix for WordPress Plugin Activation Error – “Headers Already Sent”

Leave a Reply