Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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> 
new TWTR.Widget({...

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

share|improve this question
up vote 1 down vote accepted

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.

share|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 posting your answer, you agree to the privacy policy and terms of service.

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