2016-08-05 62 views
2

我快要發瘋了:/WordPress的插件活化狀態頁面頭部已經發送錯誤

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

錯誤:插件 激活過程中產生的4個字符意外的輸出。如果您發現「頭部已經發送」的消息,問題 與聯合供稿或其它問題,請嘗試停用或刪除 這個插件

回答

1

刪除不必要的空格,換行 ,將刪除錯誤 也刪除最後

?> 

嘗試婁代碼

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

沒有多餘的空間:/ –

+0

看到我已經添加代碼 – Shafi

+0

你的編輯不會解決問題。此外,你沒有解釋他們做了什麼。 –

1

你的插件無法SIM卡該文件中的文件夾爲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 
+0

謝謝,我解決了:) –

+0

@FerdiKUCUK - 使用'ob_start'和'ob_end'是**不是一個好的解決方案**。你需要學習如何使用WP鉤子。 –