Twttr undefined


I have the twitter widget.js linked, but the console tells me it’s all undefined. Im using code from the samples in the step by step guide. I have this included at the top of the page (recommended by the guide):

<script>window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return t; js = d.createElement(s); = id; js.src = ""; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function(f) { t._e.push(f); }; return t;}(document, "script", "twitter-wjs"));</script>


The twttr variable is defined by setting {{window.twttr}} at the beginning of the snippet. Have you added code resulting in the window.twttr undefined error?

The most common reason you would see twttr undefined is trying to access functions contained in Twitter’s widgets JavaScript before the JavaScript is available on the page. The referenced snippet sets up a ready function to receive code to be executed after Twitter’s widgets JavaScript is available.


Thanks for your tip. I figured this one out. I wish the twitter documentation was more clear. The twttr.widgets are to fit between the twttr.ready like below.

twttr.ready(function(){ twttr.widgets.createShareButton( '', document.getElementById('new-button'), { count: 'none', text: 'Sharing a URL using the Tweet Button' }).then(function (el) { console.log("Button created.") }); });