WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to build my first plugin but am receiving the following error:

Warning: Cannot modify header information - headers already sent by (output started at /wp-admin/includes/template.php:1642) in /wp-includes/pluggable.php on line 876

But here's the thing: template.php isn't 1600 lines long and pluggable doesn't have any whitespace at that point.

My plugin code is as follows:

Plugin Name: Test 
Plugin URI: http://www.Test.com
Description: Test
Author: Test
Version: 1.0 
Author URI: http://www.Test.com

function Test_admin() {  
function Test_admin_actions() { 
    $icon_url = "";
    add_menu_page( "Test", "Test", "switch_themes", "Test", "Test_admin", $icon_url, 58 );
add_action('admin_menu', 'Test_admin_actions');

The admin.php file is currently empty.

The plugin adds a Test menu option in the admin page just before the Appearance option. When you click on it, you should theoretically get a white page but instead, you get the error.

So I'm pretty dumbfounded by this. I've disabled, deleted, and reinstalled my plugin to no avail.

Any ideas?

share|improve this question
So the error disappears after the plugin is deactivates? It is definitely a problem with this plugin? – shea Jan 17 '13 at 4:50
Yes. This error happens uniquely when clicking the Test menu option that the plugin adds. – Sweepster Jan 17 '13 at 4:52
It appears that something is trying to use the wp_redirect() function after the admin header has been printed – shea Jan 17 '13 at 4:55
What would that be? My plugin doesn't do anything. My entire code is what is posted. – Sweepster Jan 17 '13 at 4:57
Have you tried changing the names of your functions? Possible conflict? – shea Jan 17 '13 at 4:58
up vote 2 down vote accepted

I'll guess your include is failing. If it's in the same directory as your main plugin file, try:

include( plugin_dir_path(__FILE__) . '/admin.php' );
share|improve this answer
Yes, this could be the reason +1 – shea Jan 17 '13 at 4:59
That did the trick! – Sweepster Jan 17 '13 at 5:04

It's most likely a space after the closing ?> tag. The WordPress Codex recommends that you drop the closing tag completely.

share|improve this answer
Negative. No spaces after the closing tag. Even with the closing tag removed, the error persists. – Sweepster Jan 17 '13 at 4:41
It's a good suggestion all the same, it's good practice to leave out the closing tag to avoid whitespace and headers sent errors more easily. – t31os Feb 3 '14 at 18:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.