0

I'm trying to implement a taboola ad unit in a shortcode function, but I'm getting a syntax error. Below is the function that creates the shortcode. The code is in my functions.php file.

Can someone please help me figure out 'why' I'm getting the error and help me correct it?

/**
 * in article placement
 */

function contentMid(){
return '<div id="xxxx-xxxxxx"></div>
<script type="text/javascript">
  window._taboola = window._taboola || [];
  _taboola.push({
    mode: 'xxxxxxx-xxxxx',
    container: 'xxxxxx-xxxxxxx',
    placement: 'one word word',
    target_type: 'mix'
  });
</script>';
}
add_shortcode('contentMid', 'contentMid');

1 Answer 1

2

You need to escape your quotes, or use doubles, or use heredoc:

// Escaped
return '<div id="xxxx-xxxxxx"></div>
<script type="text/javascript">
    window._taboola = window._taboola || [];
    _taboola.push({
        mode: \'xxxxxxx-xxxxx\',
        container: \'xxxxxx-xxxxxxx\',
        placement: \'one word word\',
        target_type: \'mix\'
    });
</script>';

// Doubles
return '<div id="xxxx-xxxxxx"></div>
<script type="text/javascript">
    window._taboola = window._taboola || [];
    _taboola.push({
        mode: "xxxxxxx-xxxxx",
        container: "xxxxxx-xxxxxxx",
        placement: "one word word",
        target_type: "mix"
    });
</script>';

// Heredoc
return <<<html
<div id="xxxx-xxxxxx"></div>
<script type="text/javascript">
    window._taboola = window._taboola || [];
    _taboola.push({
        mode: "xxxxxxx-xxxxx",
        container: "xxxxxx-xxxxxxx",
        placement: "one word word",
        target_type: "mix"
    });
</script>
html;
1
  • Thank your TheDeadMedic for your help and the options you provided. I used the escape method and it worked perfectly!
    – Mr. B
    Commented Feb 5, 2015 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.