How to resolve this error caused by plugin: Warning: Cannot modify header information****

Posted on 2009-02-21
Last Modified: 2012-05-06
Alright, I've been beating my brains out trying to fix this one but it's not getting any better.

I'm working with someone on a plugin that will insert a social bookmarking menu into each wordpress post. It allows them to choose which sites they'd like to display, as well as whether to display the menu before or after each post.

The problem is, the plugin will activate fine. However, once it's activated nobody can comment without it throwing a mysql error:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampplite\htdocs\wordpress\wp-content\plugins\wp-social-bookmark-menu\wp-social-bookmark-menu.php:1) in C:\xampplite\htdocs\wordpress\wp-includes\pluggable.php on line 850

Now, even though it gives that error... It actually still posts the comment. Also, if you try to deactivate the plugin you get the same error, but if you refresh when you get the error it shows that the plugin has been deactivated.

I'm using Xampp and wordpress 2.7.1

I know that this error is most generally caused by excess whitespace betweeen php code blocks... but I can't find any extra space before or after the <? or ?>

I've attached the full code for the plugin below:


Plugin Name: wp social bookmark menu

Plugin URI:

Description: Add a social bookmarking links. Thanks to <a target="_blank" href="">eight7teen</a> for original ideaa and base code. See <a href="options-general.php?page=wp-social-bookmark-menu.php">configuration panel</a> for more settings. For more info and plugins visit <a href="">Labs Saidmade</a>

Version: 1.0

Author: Giovambattista Fazioli

Author URI:


//if(basename(__FILE__) == basename($_SERVER['SCRIPT_FILENAME'])) die();



define('OPTIONSTITLE','Social Bookmark Menu');


define('WP_CONTENT_URL', get_option('siteurl').'/wp-content');





 * The default options are stored in this array (key => default value)

 * The global plugin variables have a $wpp_ prefix (wordpress plugin)


$wpp_options = array(

'position' => 'onthebottom','bookmark' => array('scriptstyle','blinklist','delicious','digg','furl','reddit','yahoomyweb','stumbleupon','technorati','mixx','myspace','designfloat','facebook')



 * Add to Wordpress options database


add_option(OPTIONSKEY, $wpp_options, OPTIONSTITLE);


 * re-Load options


$wpp_options = get_option(OPTIONSKEY);

// ________________________________________________________________________________________ OPTIONS




 * Add callback for adding options panel



function wpp_options_page() {

	if (function_exists('add_options_page')) {

		add_options_page(OPTIONSTITLE, OPTIONSTITLE, 8, basename(__FILE__), 'wpp_options_subpanel');




 * Draw Options Panel


function wpp_options_subpanel() {

	global $wpp_options, $_POST;

	$any_error = "";										// any error flag

	if(isset($_POST['flag_save'])) {						// have to save options

		$any_error = 'Your settings have been saved.';



		 * Check for any missing or wrong POST value


		if($_POST['position'] == '') {		

			$any_error = 'Some field is empty! Check and try again!';

			} else {

			$wpp_options['position'] = $_POST['position'];

			$wpp_options['bookmark'] = $_POST['bookmark'];

			update_option(OPTIONSKEY, $wpp_options);





	 * Show error or OK


	if($any_error != '') echo '<div id="message" class="updated fade"><p>'.$any_error.'</p></div>';





	 * You can include a separate file: include ('options.php');



?><div class="wrap">

    <h2>WP Social Bookmark Menu</h2>


	<form name="wp-social-bookmark-menu" id="wp-social-bookmark-menu" action="" method="post">

		<input type="hidden" name="flag_save" value="1" />


		  <table width="300" cellpadding="4" cellspacing="0">


		  <td align="right" valign="top" nowrap><label for="position">Position:</label> </td>


		  	  <input <?php echo (($wpp_options['position'] == "onthetop")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthetop" /> On the top<br/>

		  	  <input <?php echo (($wpp_options['position'] == "onthebottom")? 'checked="checked"' : ""); ?> name="position" id="position" type="radio" value="onthebottom" /> On the bottom





		   <td align="right" valign="top" nowrap><label for="position">Choose Bookmark:</label> </td>


		  	  <input <?php echo (@in_array("scriptstyle", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="scriptstyle" /> Script & Style <span class="scriptstyle"></span><br/>

			  <input <?php echo (@in_array("blinklist", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="blinklist" /> Blinklist <span class="blinklist"></span><br/>

			  <input <?php echo (@in_array("delicious", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="delicious" /> <span class="delicious"></span><br/>

			  <input <?php echo (@in_array("digg", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="digg" /> Digg this! <span class="digg"></span><br/>

			  <input <?php echo (@in_array("furl", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="furl" /> Furl <span class="furl"></span><br/>

			  <input <?php echo (@in_array("reddit", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="reddit" /> Reddit <span class="reddit"></span><br/>

			  <input <?php echo (@in_array("yahoomyweb", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="yahoomyweb" /> Yahoo MyWeb <span class="yahoomyweb"></span><br/>

			  <input <?php echo (@in_array("stumbleupon", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="stumbleupon" /> StumbleUpon <span class="stumbleupon"></span><br/>

			  <input <?php echo (@in_array("technorati", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="technorati" /> Technorati <span class="technorati"></span><br/>

			  <input <?php echo (@in_array("mixx", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="mixx" /> Mixx <span class="mixx"></span><br/>

			  <input <?php echo (@in_array("myspace", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="myspace" /> MySpace <span class="myspace"></span><br/>

			  <input <?php echo (@in_array("designfloat", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="designfloat" /> DesignFloat <span class="designfloat"></span><br/>

			  <input <?php echo (@in_array("facebook", $wpp_options['bookmark'])? 'checked="checked"' : ""); ?> name="bookmark[]" id="bookmark[]" type="checkbox" value="facebook" /> Facebook <span class="facebook"></span><br/>




		  <td colspan="2"><div class="submit"><input type="submit" value="Save Settings" /></div></td>






	  	<p>Visit <a target="_blank" href=""></a>, <a target="_blank" href=""></a> and <a target="_blank" href=""><img align="absmiddle" src="" border="0" /></a> for more information about author and WordPress Plugin</a>






 * Filter


function position_menu($content) {

	global $wpp_options;


	$title = get_the_title();

	$perma = get_permalink();

	$social = '<div class="wp-social-bookmark-menu"><ul class="socials">'.

	(in_array("scriptstyle", $wpp_options['bookmark'])?

	'<li class="script-style"><a href="'.$perma.'&title='.$title.'" title="Submit this to Script & Style"> </a></li>' : '').


	(in_array("blinklist", $wpp_options['bookmark'])?

	'<li class="blinklist"><a href="'.$perma.'&Title='.$title.'" title="Share this on Blinklist"> </a></li>' : '').


	(in_array("delicious", $wpp_options['bookmark'])?

	'<li class="delicious"><a href="'.$perma.'&title='.$title.'" title="Share this on"> </a></li>' : '').


	(in_array("digg", $wpp_options['bookmark'])?

	'<li class="digg"><a href="'.$perma.'&title='.$title.'" title="Digg this!"> </a></li>' : '').


	(in_array("furl", $wpp_options['bookmark'])?

	'<li class="furl"><a href="'.$title.'&u='.$perma.'" title="Share this on Furl"> </a></li>' : '').


	(in_array("reddit", $wpp_options['bookmark'])?

	'<li class="reddit"><a href="'.$perma.'&title='.$title.'" title="Share this on Reddit"> </a></li>' : '').


	(in_array("yahoomyweb", $wpp_options['bookmark'])?

	'<li class="yahoo"><a href="'.$title.'&u='.$perma.'" title="Save this to Yahoo MyWeb"> </a></li>' : '').


	(in_array("stumbleupon", $wpp_options['bookmark'])?

	'<li class="stumble"><a href="'.$perma.'&title='.$title.'" title="Stumble upon something good? Share it on StumbleUpon"> </a></li>' : '').

	(in_array("technorati", $wpp_options['bookmark'])?

	'<li class="technorati"><a href="'.$perma.'" title="Share this on Technorati"> </a></li>' : '').


	(in_array("mixx", $wpp_options['bookmark'])?

	'<li class="mixx"><a href="'.$perma.'&amp;title='.$title.'" title="Share this on Mixx"> </a></li>' : '').


	(in_array("myspace", $wpp_options['bookmark'])?

	'<li class="myspace"><a href="'.$perma.'&amp;t='.$title.'" title="Post this to MySpace"> </a></li>' : '').


	(in_array("designfloat", $wpp_options['bookmark'])?

	'<li class="designfloat"><a href="'.$perma.'&amp;title='.$title.'" title="Submit this to DesignFloat"> </a></li>' : '').


	(in_array("facebook", $wpp_options['bookmark'])?

	'<li class="facebook"><a href="'.$perma.'&amp;t='.$title.'" title="Share this on Facebook"> </a></li>' : '').



	if($wpp_options['position'] == "onthetop") return $social.$content;

	else return $content.$social;


add_action('wp_head', 'add_styles');

function add_styles() {

	echo "\n".'<!-- Start Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";

	if(@file_exists(TEMPLATEPATH.'/styles.css')) {

		wp_register_style('wp-social-bookmark-menu', get_stylesheet_directory_uri().'/styles.css', false, VERSION, 'all');

	} else {

		wp_register_style('wp-social-bookmark-menu', plugins_url('wp-social-bookmark-menu/styles.css'), false, VERSION, 'all');



	echo '<!-- End Of Code Generated By WP-Social-Bookmark-Menu '.VERSION.' -->'."\n";


function bookmark_styles() {

echo "<style type='text/css'>

form#wp-social-bookmark-menu span {

background:url(".WP_PLUGINS_PATH."sprite-trans.png) no-repeat;





span.scriptstyle { background-position:-400px bottom !important; }

span.mixx { background-position:-250px bottom !important; }

span.facebook { background-position:-450px bottom !important; } { background-position:-250px bottom !important; }

span.myspace { background-position:-200px bottom !important; }

span.blinklist { background-position:-600px bottom !important; }

span.yahoomyweb { background-position:-650px bottom !important; }

span.delicious { background-position:left bottom !important; }

span.stumbleupon { background-position:-50px bottom !important; }

span.reddit { background-position:-100px bottom !important; }

span.digg { background-position:-500px bottom !important; }

span.furl { background-position:-300px bottom !important; }

span.technorati { background-position:-700px bottom !important; }

span.designfloat { background-position:-550px bottom !important; }



add_action('admin_head', 'bookmark_styles');

add_action('admin_menu', 'wpp_options_page');

add_filter('the_content', 'position_menu');


Open in new window

Question by:blatantwaste
    LVL 3

    Author Comment

    I just realized it would probably be more helpful just to post a zip folder with the entire plugin rather than just the php code portion, so you can download the plugin from here:
    LVL 39

    Accepted Solution

    Save the file as an ascii file, not as unicode/utf-8. It contains some "invisible" characters at the start.

    $f = fopen('wp-social-bookmark-menu.php','r');
    $data = fread($f,10);
      echo ord($data[$i]).' '.$data[$i].'<br />';


    239 ï
    187 »
    191 ¿
    60 <
    63 ?
    112 p
    104 h
    112 p
    LVL 39

    Expert Comment

    by:Roger Baklund
    These "invisible" characters are known as the BOM, it is normal that these exist in unicode encoded files.

    EF BB BF == 239, 187, 191
    LVL 3

    Author Closing Comment

    Not sure if ASCII is the same as ANSI, but my text editor didn't have an option for ASCII... So I saved it in ANSI format and it's working fine now. Thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    I want to start by talking about the use of plug-ins for WordPress. I started a web-site for a company I was working for a few years ago; I had extremely basic knowledge of HTML. I am a Graphic Designer by trade so I invited the opportunity as a cha…
    WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
    The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
    The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now