admin管理员组

文章数量:1425664

When i'm going to active my plugin that i create for sample , wordpress got me 1 unexpected output during activation !

This plugin actually has nothing but a Shortcode that will echo Hello !

I followed these steps but nothing didn't change :

1- save My plugin with other names ( Folder and plugin name etc.)

2- Copy/paste codes in other php file that i created in Cpanel file manager

3- changing my encode to UTF-8 (Without BOM ) in Notepad++

Please help me with this issue. my plugin code is

<?php
/*
 * Plugin Name:       ARU V1
 * Plugin URI:        Mysiteadress
 * Description:       arv
 * Author:            Myname was here
 * Author URI:        Mysiteadress
 * Version:           1.5
 * Text Domain:       pnl
 */


function upnl() { 
echo "hello";

 } 

add_shortcode( 'pnlsc', 'upnl' ); 

?>

When i'm going to active my plugin that i create for sample , wordpress got me 1 unexpected output during activation !

This plugin actually has nothing but a Shortcode that will echo Hello !

I followed these steps but nothing didn't change :

1- save My plugin with other names ( Folder and plugin name etc.)

2- Copy/paste codes in other php file that i created in Cpanel file manager

3- changing my encode to UTF-8 (Without BOM ) in Notepad++

Please help me with this issue. my plugin code is

<?php
/*
 * Plugin Name:       ARU V1
 * Plugin URI:        Mysiteadress
 * Description:       arv
 * Author:            Myname was here
 * Author URI:        Mysiteadress
 * Version:           1.5
 * Text Domain:       pnl
 */


function upnl() { 
echo "hello";

 } 

add_shortcode( 'pnlsc', 'upnl' ); 

?>
Share Improve this question asked Jun 9, 2019 at 12:27 TheXrionTheXrion 57 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

It is bad practice to end a PHP only file with the PHP closing tag (?>) as it may lead to a new line or any other character being output before the headers or other functions and thus creating problems like the one you mention.

Whenever you create/edit a PHP file, don't close it, if you have to include HTML, close and open the PHP tags again.

https://php/basic-syntax.instruction-separation

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.

Best regards.

本文标签: phpPlugin Generate Unexpected output during activation