0

From what I have read in the search function, the javascript absolutely needs . This script works fine when i sub in sample vaiables for disqus_identifier and disqus_title but when I try to use a php variable that has been stored in the page, it breaks!

<div id="disqus_thread"></div>
<script>
    var disqus_shortname = 'sample';

    var disqus_config = function () {
      this.page.remote_auth_s3 = '*********';
      this.page.api_key = '********';
}
</script>

<script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_identifier = "/posts/"<?php var_dump($postid); ?>;
       var disqus_title = <?php var_dump($title); ?>;

       /* * * DON'T EDIT BELOW THIS LINE * * */
       (function() {
         var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
      dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
       })();
</script>

<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
1
  • var disqus_title = <?php var_dump($title); ?>"; There's an extraneous quote there Commented Aug 13, 2014 at 20:44

1 Answer 1

3

var_dump() isn't what you want, as it "dumps information about a variable", instead of just echoing the contents. (Docs) You want to take the $postid and render the literal string contained within the variable.

use

<?php echo $postid ?>

or

<?=$postid?>

instead.

You also need to surround it with quotes if you want the string literal and not the int representation, so

var post_id = "<?=$post_id?>";

will work or

var post_id = "This <?=$post_id?> is great";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.