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.
Dan | gteh answers:
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.
Edwin comments:
Thanks Dan!
Daniel Yoen answers:
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");