2
votes

I'm about to go crazy :/

<?php
/*
Plugin Name: TEST Plugin
Description: test desc
Author: test
Author URI: test
Plugin URI: test
*/
echo"test";
?>

Error : The plugin generated 4 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

2

2 Answers

2
votes

remove unnecessary white space or line break that will remove the error also remove last

?>

Try bellow code

<?php
/*
    Plugin Name: TEST Plugin
    Description: test desc
    Author: test
    Author URI: test
    Plugin URI: test
*/
ob_start();
echo 'test';
ob_clean();
1
votes

Your plugin cannot simply echo "test" in the file. That is what is generating the unexpected output.

Remove that.

All output that a plugin generates should be inside of functions, which typically get called by using one of the many WordPress Hooks.

Here's a super-simple, (and useless) example:

<?php
/*
Plugin Name: TEST Plugin
Description: test desc
Author: test
Author URI: test
Plugin URI: test
*/

// Hooks into the WordPress wp_head action
add_action('wp_head', 'my_wp_head_function');

// Runs when the WordPress init action runs
function my_wp_head_function() {
    echo "test";
}

// ... etc

// Also - DO omit the closing PHP tag.  That is now considered best practice