logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
Need Proper Syntax For Functions.php Snippet To Fix Error

Hi,

When I use this code snippet in functions php it results in an error:
Parse error: syntax error, unexpected T_STRING in /home/edwin/public_html/domain.com/wp-content/themes/mytheme/functions.php on line 537


function showcustomcontent() {
return '
<div id="customcontent">
<h2 class="headline">This is a headline</h2>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut nibh ante. Mauris ac semper neque.
<a class="track" href="http://www.domain.com/information" onclick="_gaq.push(['_trackEvent', 'Call To Action Links', 'Click', 'Inline Txt']);">anchor text</a> hendrerit consectetur lectus.
</div>
';
}

add_shortcode('customcontent', 'showcustomcontent');


The problem is related to the event tracking stuff, but I don't know how to fix this.

Your help is much appreciated.




This question has been answered.

Edwin | 06/29/12 at 10:32am Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    06/29/12
    10:38am
    Dan | gteh says:

    replace it with this:



    function showcustomcontent() {

    return '

    <div id="customcontent">

    <h2 class="headline">This is a headline</h2>

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut nibh ante. Mauris ac semper neque.

    <a class="track" href="http://www.domain.com/information" onclick="_gaq.push([\'_trackEvent\', \'Call To Action Links\', \'Click\', \'Inline Txt\']);">anchor text</a> hendrerit consectetur lectus.

    </div>

    ';

    }



    add_shortcode('customcontent', 'showcustomcontent');


    You need to escape the single quotes inside the google analytics code. You've opened the function with ' and closed it with ' so you can't use ' inside the function unless you escape it with a slash first.

    Previous versions of this answer: 06/29/12 at 10:38am

    • 06/29/12 10:43am

      Edwin says:

      Thanks Dan!

  • avatar
    Last edited:
    06/29/12
    10:40am
    Daniel Yoen says:

    try this :


    function showcustomcontent() {

    return "

    <div id=\"customcontent\">

    <h2 class=\"headline\">This is a headline</h2>

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ut nibh ante. Mauris ac semper neque.

    <a class=\"track\" href=\"http://www.domain.com/information\" onclick=\"_gaq.push(['_trackEvent', 'Call To Action Links', 'Click', 'Inline Txt']);\">anchor text</a> hendrerit consectetur lectus.

    </div>

    ";

    }



    add_shortcode("customcontent", "showcustomcontent");

This question has expired.



Gabriel Reguly, Edwin, Hai Bui, Arnav Joy, Daniel Yoen voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.