1

I have Twitter's own widget set to load on a website, which works just fine. However, on my WP-powered blog the script is included but not rendered. I call it inside an empty div like this:

<?php include $_SERVER['DOCUMENT_ROOT'].'/twtr-widget.html' ?>

But it appears in the page source as HTML (I'm putting '...' to save room):

<script src="http://widgets.twimg.com/j/2/widget.js"></script> 
<script> 
new TWTR.Widget({...
...</script>

In other words, the script is not being executed. Why is this?

1

You cannot process Javascript with the PHP interpreter - the PHP interpreter will ignore anything which is not bound by <?php/?> and will simply return the include as part of the document you are serving.

| improve this answer | |
  • I thought this to be the case as well, yet putting the Javascript straight into the template yields the exact same result. Any other ideas? – Isaac Lubow Dec 24 '10 at 16:50
  • @Isaac Lubow What happens when you load the page with the widget script included? Do you see any Javascript errors? – danlefree Dec 24 '10 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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