Wordpress插件激活标头已发送错误

时间:2016-08-05 18:01:46

标签: wordpress header

我要发疯了:/

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

错误:插件在此期间生成了4个意外输出字符   激活。如果您注意到“已发送标头”消息,则会出现问题   如果有联合供稿或其他问题,请尝试停用或删除   这个插件

2 个答案:

答案 0 :(得分:2)

删除不必要的空格或换行符 这将删除错误 也删除最后一次

?>

试用下面的代码

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

答案 1 :(得分:1)

您的插件不能只是文件中的echo "test"那是产生意外输出的原因。

删除它。

插件生成的所有输出都应该在函数内部,通常使用许多WordPress Hooks中的一个来调用。

这是一个超级简单,(无用)的例子:

<?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