0

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.com
 * Description:       arv
 * Author:            Myname was here
 * Author URI:        Mysiteadress.com
 * Version:           1.5
 * Text Domain:       pnl
 */


function upnl() { 
echo "hello";

 } 

add_shortcode( 'pnlsc', 'upnl' ); 

?>
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.net/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.

1
  • 1
    Thankyou for Provide a solution , But i removed space in add_shortcode( 'pnlsc', 'upnl' ); this line between comma and 'pnlsc' and 'upnl' then everything goes well and the error didn't occurred again.
    – TheXrion
    Jun 9 '19 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.