15 Useful Twitter Hacks and Plug-Ins For WordPress

January 24th, 2012 WP Plugins 6 Comments

Since its launch in 2006, Twitter has grown to create what most people would call a social media revolution. By the very nature of the short messages it hosts, Twitter is a wonderful marketing and promotion tool that no serious blogger can ignore.

In this article, we have compiled 15 most useful Twitter plug-ins, hacks and tips for WordPress to help you get the most out of Twitter in your WordPress blog.

You may want to take a look at the following related posts:

[Editor's note: A must-have for professional Web designers and developers: The Printed Smashing Books Bundle is full of practical insight for your daily work. Get the bundle right away!]

1. WordPress Hacks For Twitter

WordPress plug-ins are good, but if you have 50 different plug-ins active on your blog, you should obviously expect longer loading times and even some inconvenience. This is why we love hacks! First let’s dive deep into WordPress and see what hacks can do to enhance our blogging experience. In the second part of this article, we will also show you some useful Twitter plug-ins for your WordPress blog.


Because of the restriction on character numbers in Twitter, you have to use a URL shortener when tweeting URLs. So, to help your readers tweet about your posts, you should definitely provide short URLs for all of your posts.

Here’s how to automate that task:

Open your functions.php file and paste the following code:

1 function getTinyUrl($url) {
2     $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
3     return $tinyurl;
4 }

Once done, paste this in your single.php file, within the loop:

1 <?php
2 $turl = getTinyUrl(get_permalink($post->ID));
3 echo 'Tiny Url for this post: <a href="'.$turl.'">'.$turl.'</a>'
4 ?>

To see this in action, visit my website, WpVote, and look at any post.

Source: How to: Automatically provide TinyUrls for your WordPress blog posts


If people like your blog, they would probably also enjoy your tweets. Displaying your latest tweets on your WordPress blog is a good way to gain new subscribers. A plug-in can do that, but for such a simple task, I prefer a hack. This one grabs your latest tweet and displays it on your blog.

This ready-to-use code can be pasted anywhere in your theme files. Just don’t forget to change the value of the $username on line 4. The $prefix and $suffix variable can be used to insert a title, and the div element can be used for further CSS styling.

01 <?php
03 // Your twitter username.
04 $username = "TwitterUsername";
06 // Prefix - some text you want displayed before your latest tweet.
07 // (HTML is OK, but be sure to escape quotes with backslashes: for example href=\"link.html\")
08 $prefix = "<h2>My last Tweet</h2>";
10 // Suffix - some text you want display after your latest tweet. (Same rules as the prefix.)
11 $suffix = "";
13 $feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
15 function parse_feed($feed) {
16     $stepOne = explode("<content type=\"html\">", $feed);
17     $stepTwo = explode("</content>", $stepOne[1]);
18     $tweet = $stepTwo[0];
19     $tweet = str_replace("&lt;", "<", $tweet);
20     $tweet = str_replace("&gt;", ">", $tweet);
21     return $tweet;
22 }
24 $twitterFeed = file_get_contents($feed);
25 echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
26 ?>

Save the file, and your latest tweet is displayed on your blog. Nice, huh?



Because of Twitter’s success, a lot of third-parties have started promoting additional Twitter services.TwitSig is one of them. This website is very ugly but also very cool because it allows you to get an auto-updating image that displays your latest Twitter entry.

While using this image as a signature in forums would be good enough, integrating it in your WordPress blog, under your posts for example, would also be great.

  1. Go to Twitsig.com. You don’t have to register: very nice!
  2. Simply enter your Twitter username in the text field.
  3. And your Twitter image is ready, displaying your latest tweet. The image is automatically updated when you update your Twitter status.
  4. Open any of your WordPress theme files and paste the following code (make sure to replace my username with yours!):


Twitter is definitely a great way to gain exposure on the Web. This is why I created a fancy “Send to Twitter” button and implemented it on my blogs (see links at the bottom of the article). Go here if you’d like to see this hack in action.

  1. Open the single.php file in your theme.
  2. Paste the following code where you’d like your Twitter button to appear:
    1 <a href="http://twitter.com/home?status=Currently reading <?php the_permalink(); ?>" title="Click to send this page to Twitter!" target="_blank"><img src="send-to-twitter.png" alt="" /></a>

Some time ago, in my “Mastering WordPress shortcodes” article here on Smashing Magazine, I showed you how to create a “Send to Twitter” WordPress shortcode. I also wrote an article on Pro Blog Design about creating a “Send to Twitter” WordPress widget. You can read that tutorial here!


Visitors coming to my blogs from Twitter now represent something like 10% of all my traffic, which is quite a lot. Because many Twitter users re-tweet blog posts that they like, it may be a very good idea to detect Twitter visitors, welcome them and, of course, remind them that their re-tweets are appreciated.

To do this, open your single.php file and paste these lines where you’d like your “Welcome Twitter user” message to be displayed.

1 <?php
2 if (strpos("twitter.com",$_SERVER[HTTP_REFERER])==0) {
3     echo "Welcome, Twitter visitor! If you enjoy this post, don't hesitate to retweet!";
4 }
5 ?>

This code will detect readers coming from Twitter and display the message only to them.


We already showed you how to display your latest tweet on your blog, in your sidebar for example. Another good way to introduce readers to your Twitter updates is to create a dedicated page for displaying your tweets, using the powerful “Page template” WordPress option.

To perform this hack, you need to know how to create and use page templates. If you’re not familiar with this, this article will tell you all you need to know.

Here’s the code to create a Twitter page template. Paste it in a new file, name the file something liketwitter-page.php, for example, and then add it to your blog.

01 <?php
03 /*
04 Template Name: Twitter page
05 */
07 get_header();
09 include_once(ABSPATH.WPINC.'/rss.php');
12 get_sidebar();
13 get_footer();
14 ?>

This code uses the wp_rss() function from WordPress core, which is an RSS reader. In the first argument I pass my Twitter RSS feed, and in the second argument I determine the number of entries to display.


I was pretty interested in the Twittar plug-in when it was first released and decided to look at the source to see how it works. Being a die-hard WordPress hack fanatic, I decided to create a hack using the Twittar code.

Follow these simple instructions to use Twitter avatars in your blog comments without a plug-in:

  1. The first thing is to get the functions file here.
  2. Once you have it, unzip the archive and open the twittar.php file. Select all of its contents and paste it in the functions.php file in your theme.
  3. Now, open your comments.php file and find the comments loop. Then, just paste the following line where you’d like the Twitter avatars to be displayed:
    1 <?php twittar('45', 'default.png', '#e9e9e9', 'twitavatars', 1, 'G'); ?>

SourceHow to: Use Twitter avatars in comments

2. WordPress Plug-Ins For Twitter

Twitter Updater
Are you using Twitter to notify readers about your new blog posts, or even old ones that you’ve updated? If so, then Twitter Updated is definitely something to consider. The plug-in automatically sends an update status request to Twitter when you create or modify a post. Text is customizable, and the plug-in provides many options.

Twit this
The Twit This plug-in makes it easy for readers to tweet about your blog posts by creating a “Share on Twitter” link on your blog. When someone clicks on it, your blog post’s URL is automatically sent to Twitter, and the visitor can enters a description before sending the tweet to his or her friends.

Twit it up
Twit it up is a simple AJAX-powered WordPress plug-in that basically does the same thing as Twit this: allows readers to tweet one of your posts directly from your blog by clicking a simple link.

Twit-Twoo is a very useful for bloggers because it allows you to tweet friends directly from your WordPress dashboard. Particularly great if you spend a lot of time on your WordPress dashboard!

Twitter Tools
Twitter Tools, created by Alex King, is one of the most popular Twitter plug-ins for WordPress. It completely integrates Twitter in your WordPress blog, allowing you to archive your tweets, create a blog post from each of your tweets and post tweets from your admin dashboard or sidebar. It also allows you to create a daily digest of tweets; very nice if you tweet a lot!

Twittar was released here on Smashing Magazine back in January. Remember it? This plug-in integrates Twitter avatars in the comment template of your WordPress blog. Definitely a plug-in to consider if you and your readership often use Twitter! And don’t worry if any of your readers don’t use Twitter (yet), Twittar automatically displays gravatars if no Twitter avatar is available.

Since its release only one month ago, the Tweetbacks plug-in has created a mini-revolution in the blogging world. While your WordPress blog can automatically notify you when bloggers discuss your posts on their own blogs, via Trackbacks, it can’t notify you when people discuss your posts on Twitter. That’s why Tweetbacks is so great: it automatically imports tweets about your posts and lets you display them either as comments or separately.

Source: http://wp.smashingmagazine.com/2009/03/04/15-useful-twitter-plugins-and-hacks-for-wordpress/


Introducing Tweetbacks Plugin for WordPress
Lessons Learned From Maintaining a WordPress Plug-In

About admin

» has written 52 posts


  1. Stine says:

    Salem March 30th, 2009 12:33 pm I love this, and it has been really euhpfll. There are two things I was wondering, however Is it possible to1. Make the Tweet this! image load a page with a tinyurl, rather than the full length of the blog post? I messed around a little bit and, knowing absolutely no php, didn’t get very far.2. make the Tweet this! image load only when someone comes from twitter? This way, instead of having text, I could just have that image? I tried just pasting the html code in the midst of the php, which apparently is NOT how it works.Could someone email me with replys at salem (AT) technoheads.org? I’d really appreciate it, and I’m not sure if the author of this post responds to comments.

  2. Keval says:

    James May 25th, 2011 2:48 pm Hello!I have used a few of these codes with success. However, I am a bit edeudflbd on the code about automatically creating tiny urls for one’s posts.First of all I am blind and use speech software. I perused the single.php file and though it’s doesn’t contain a lot of stuff in it, I am at a lost as to where I should put the single.php code exactly. I am viewing the single.php file in notepad and unfortunately it somehow messes with the formating of the lines. (I think. Then again, being new to php codes, or wp codes, perhaps that is how it’s suppose to show up.) Could someone paste the exact location of this code?I am also a bit uncertain as to the location of the tiny url once it is created? I think it is suppose to show up on the single post page? Additionally, is this tiny url code and the Tweet back code suppose to work with each other? Like the tiny url is displayed right next to the Tweet back button so the user only needs to copy and paste the tiny url, click the send to twitter button, and paste it into their twitter interface to tweet?If this is the case, couldn’t a shortcode be created as as it was for the send to twitter’ button explained in this article? Like [sendtotwitter]This might be a possible solution for me if I am not able to make the single.php work.And if I am way off base, could someone please explain?Thanks in advance :) Great article!

  3. Hot Carl says:

    I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all web owners and bloggers made good content as you did, the web will be a lot more useful than ever before.

  4. I just want to mention I’m beginner to blogging and site-building and honestly loved this web blog. More than likely I’m going to bookmark your blog . You definitely have wonderful articles. Bless you for revealing your blog site.

  5. xbox 360 slim 250 gb says:

    Found your content very appealing indeed. I truly really enjoyed reading through it so you make very some good points. I will bookmark this site for that potential! Relly terrific content.