Search code examples
wordpresspluginsactivation

I can't activate my WordPress plugin on localhost


I am trying to activate a tiny plugin on WordPress that is running on localhost but it runs into the following error:

The plugin generated 6 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.

<?php
/*
Plugin Name: myphoto Plugin
Description: A plugin to retrieve photos and share them on the wordpress.
Version: 1.0
Author: Saeed pirdost
Copyright: 2012,  Saeed pirdost  
*/
?>
<?php
myprint();
function myprint()
{
    echo "hello";
}
?>

Solution

  • Try remove some things and use a suitable hook.

    <?php // remove all spaces up of here too
    /*
      Plugin Name: RePhotosPic Plugin
      Description: A plugin to retrieve photos and share them on the wordpress.
      Version: 1.0
      Author: Saeed pirdost
      Copyright: 2012,  Saeed pirdost
     */
    
    // remove     ?> <?php
    
    add_filter('admin_notices', 'hello');
    
    function hello()
    {
        echo 'Hello';
    }
    
    // remove ?>
    

    UPDATE:

    Remove myprint(); place it inside a WP hook too. Like this:

    add_filter('admin_notices', 'myprint');
    
    function myprint()
    {
        echo "hello";
    }