I have always an error with my plugin code and I don't get it:

this is the error

Parse error: syntax error, unexpected 'stoerer' (T_STRING), expecting ';' or ',' in /opt/lampp/htdocs/wordpress/wp-content/plugins/stoerer/stoerer.php on line 85

function stoerer() {
    echo  "<button class="stoerer" id="stoerer" onclick="buttonShow()">Ich bin ein Störer</button>";

  echo "<!-- Und dann die Info-Box --> 
    <div id="infoBox">
    <button class="cross" type="button" onclick="buttonHide()">X</button>"";
     "<h2> Hallo, </h2>" ; 
     "Lorem Ipsum"";

add_action('wp_footer', 'stoerer');

It's a PHP syntax error. In PHP double quotes are used to open and close Strings. Since the string you're trying to echo includes quotes you need to either properly escape the quotes so that they're not interpreted as trying to close the string, or use single and quotes for the string, since double quotes are not interpreted that way when used inside single quotes.

Also, you seem to be using semi-colons to end lines, but if you start a new line you need to echo that line too. Also, your div is missing a closing tag.

This code resolves both those issues:

function stoerer() {
    echo '<button class="stoerer" id="stoerer" onclick="buttonShow()">Ich bin ein Störer</button>';
    echo '<!-- Und dann die Info-Box -->';
    echo '<div id="infoBox">';
    echo '<button class="cross" type="button" onclick="buttonHide()">X</button>';
    echo '<h2> Hallo, </h2>'; 
    echo 'Lorem Ipsum';
    echo '</div>';
add_action( 'wp_footer', 'stoerer' );

Just because you mentioned you were a beginner on a previous question, I would suggest finding some tutorials online for PHP. Entry level tutorials or courses will cover this sort of thing.

  • After hours of spending in tutorials it's sometimes more easier when a Pro helps you with his experience :) I made it. Thank you so much you're my hero for today
    – tmze
    Apr 28 '20 at 8:04

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.