CreatiFace.com

How to Embed Tweets on WordPress without a Plugin

If you are an active Twitter user, you may often find lots of interesting tweet that you want to share on your website / blog.

Thankfully, Twitter has provided an easy way that will allow you to embed fully functional tweets into your website easily, and if you run a WordPress-based website, here’s how:

embed tweets on wordpress

Include Twitter Widget.js

First we will insert twitter widget library using wp_enque_script.

Since the tweet will most likely be embedded in a page and a post, thus we will only load and insert the library only when the page and the post is being displayed.

Put the following code in your functions.php.

function embed_tweets() {
    if (is_page() || is_single()) {
        wp_register_script( 'twitter_widgets', 'http://platform.twitter.com/widgets.js', '', '', '');
        wp_enqueue_script('twitter_widgets');
    }
}
add_action('wp_enqueue_scripts', 'embed_tweets');

That’s all the code we need. Now, we only need to embed the tweet.

Embed the Tweet

Follow this steps, to embed the tweet:

  1. First sign in to your twitter account, obviously
  2. Find an interesting tweet you’d like to embed
  3. Open the tweet and click on “Details
  4. Find the “Embed this tweet” link and click on it.
  5. Copy and paste the code — excluding the widget.js script — on your blog.

Embed tweet: Copy

Now you should see the following embedded tweet:

or something like this for a conversation tweet:

What if the Widget.js is not successfully loaded?

Since the tweet is wrapped with a blockquote tag, it will still look just fine, make sure you’ve given proper styles for the blockquote in your stylesheet and here is the example of the fallback:

Fun Fact: the Twitter ecosystem recently hit more than 1.5 million registered apps. Thank you everyone for building on the platform.^JC

— Twitter API (@twitterapi) March 13, 2012

And that’s all you need to do to embed tweets on WordPress, I hope this tip can be useful for you.

2 Responses to “How to Embed Tweets on WordPress without a Plugin”

  1. Dhafian

    Very usefull dude.. Thanks for this guide.. :D

    Reply
    • Thoriq

       @Dhafian Thanks mate. :)

      Reply

Leave a Reply

We welcome for every constructive commment and respond. However, all comments will be moderated prior to publishing and rel=nofollow is in use. So, please do not use spammy ketword name

(required)

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">