最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to show content in the body with my plugin (only in frontend not backend)?

programmeradmin5浏览0评论

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

<?php
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');
?>

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

<?php
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');
?>
Share Improve this question edited Apr 28, 2020 at 13:25 Chetan Vaghela 2,4084 gold badges10 silver badges16 bronze badges asked Apr 28, 2020 at 7:22 tmzetmze 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论