ssaltman ssaltman - 7 months ago 19
PHP Question

Double slash // comments in my php wordpress theme are breaking my site

Ok, maybe I'm missing something, but I am modifying a wordpress theme functions.php file.

I am adding comments in the form of

add_shortcode( 'member', 'member_check_shortcode' );

function member_check_shortcode( $atts, $content = null ) {

if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) {

# THIS IS A COMMENT

$content = "logged in as " . $username1;

return $content;
}
return '';
}


This breaks the site and I get the error:


Parse error: syntax error, unexpected end of file in /home/politehr/public_html/wp-content/themes/politehr/functions.php on line 558


Same code with the comment removed:

add_shortcode( 'member', 'member_check_shortcode' );

function member_check_shortcode( $atts, $content = null ) {

if ( is_user_logged_in() && !is_null( $content ) && !is_feed() ) {

$content = "logged in as " . $username1;

return $content;
}
return '';
}


This does not break the site.

Same problem using double slashes: //

Same problem if I add ?> to the bottom of the file (it's not there on the 2013 theme). (edit: what I meant to say is that the problem is not solved by adding ?> to the bottom of the file)

What causes this problem?

EDIT: responding to comment:

@Ben comments in the format of /* comment */ work ok.

This site is brand new and I have no plugins activated.

It is the Twenty Thirteen theme that is standard with WP.

UPDATE:

Everyone who says that the code is somehow being minified or line breaks removed are probably correct...anyone know how to fix that and make my notepad++ editor insert line breaks? Or is WP doing this? I'm using notepad++ and then uploading via filezilla.

SOLUTION:

EOL conversion in notepad ++

Answer

Time ago, something like that happens to me. The reason was the differents EOL characters between platforms (Windows and Linux, in my case). The code I edited locally was transformed into one single line of code when uploaded, and the // comments breaks the code after them.