I just wanted to create a shortcode to count the number of times a button is pressed and i have this code in my function.php file.
function btn_cntr_shortcode(){
'<input type="button" value="Count" id="countButton" />
<p>The button was pressed <span id="displayCount">0</span> times.</p>'
'<script type="text/javascript">'
var $count = 0;
var button = document.getElementById("countButton");
var display = document.getElementById("displayCount");
button.onclick = function(){
$count++;
display.innerHTML = $count;
}
'</script>'
return $count;
}
add_shortcode('button-counter','btn_cntr_shortcode');
But am getting the following error.
Parse error: syntax error, unexpected '
'<script type="text/javascript
' (T_CONSTANT_ENCAPSED_STRING) in /home1/election/public_html/wp-content/themes/Divi/functions.php on line 4645
Any help is appreciated. Thanks in advance