Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

Most Wanted Twitter Hacks and Plugins for WordPress

Last updated on by
Elegant Themes
Most Wanted Twitter Hacks and Plugins for WordPress

Twitter has grown exponentially over the past year, and it is one of the fastest growing social networks at the moment. It is an extremely powerful marketing and promotion tool that no active blogger can ignore. Twitter has the power to make your articles go viral, and the “Twitter Effect” is something that most bloggers want. In this article, we will share some of the most wanted and extremely useful twitter hacks and plugins that will allow you to maximize your benefits from twitter.

Note: These hacks are for all user levels. Some knowledge of PHP / HTML will be required for some of the hacks. We will try to provide alternative plugins for each hack that we share to make it easy for beginners.

Display a Retweet Button with a Counter

Display a Retweet Button wit ha Counter

If you have visited an active blog, then you have seen a retweet button on their site. Majority of the time, it will be from a service known as Tweetmeme.

Snippet

One way to get this button on your site is by placing the following code in your single.php template (At a location where you want to put it).

<script type="text/javascript">
tweetmeme_source = 'wpbeginner';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"> </script>

The above code will output a big button like you see on the left hand side of this post. Make sure that you change the source to your twitter account. It is essential that you do this because it will help you get more exposure.

If you do not like the big retweet button, you can display a compact twitter button, which you can see at the end of this post. Simply paste the following code:

<script type='text/javascript'>
tweetmeme_style = "compact";
tweetmeme_source = 'wpbeginner';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"> </script>

Note: Don’t forget to change the source from wpbeginner to your username in the above code.

Plugin

Tweetmeme also offers a plugin that you can download. The plugin will allow you display these buttons within your posts. You will have an option to pick:

  • The display size (compact or large)
  • Pick the Source of this tweet (Your Username)
  • Where you want to place the button in the post

Display Twitter Follower Count as Text

There are users who absolutely hate buttons like Feedburner buttons or Twittercounter buttons. Are you one of them? Do you want to display your twitter count as text, so it blends in to your new custom design? Well then this hack is just for you.

Snippet

Paste the following code any where you want to display the count:

<?php
$tw = get_option("twitterfollowerscount");
if ($tw['lastcheck'] < ( mktime() – 3600 ) )
{
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name=wpbeginner');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
$tw['lastcheck'] = mktime();
update_option("twitterfollowerscount",$tw);
}
echo $tw['count'];
?> 

Make sure to replace wpbeginner with your twitter name.

Explanation of this code: This code will open the XML file for the username that you specify. It will look for the node followers_count, and then it will display that count on your site. Best part about this code is that it will display cached results, so it will keep the load time to the minimum.

This code was written by Rarst (@rarst)

Plugin

For those users who do not feel comfortable modifying the theme files, you can use a plugin called “Subscribers Text Counter“. This plugin will let you display the follower count in widgets, or on posts/pages. This plugin also utilizes the caching system, so it is a good solution.

Display Your Recent Tweets

Display Your Recent Tweets

It is great to give a community sense to a site by displaying recent tweets in the sidebar or on a separate page. Many blogs often display their most recent tweets in their site. This section will show you various different ways to display your recent Tweets.

Snippet

There are numerous codes on the web that will let you display recent tweets from your twitter account without a plugin. Almost all of those codes have some shortfall. Below we will share one of the snippets that will allow you to display your recent tweets with caching.

Paste the codes below, wherever you like to display the recent tweets:

Download the Code File

You must change the username from “wpbeginner” to your username. You can find this towards the very end of this code where it reads parse_cache_feed(wpbeginner, 1). The number in front represents the number of tweets that will be displayed. You can change the number to the amount that you like, but we recommend that you keep it to a minimum because this code is utilizing the Search API.

Known Issues: This snippet is using the Search API, so if your account is removed from twitter search (ofcourse by twitter), then this snippet will not display any results. Also the search API only displays tweets that were posted within the last 7 days.

For those users who are flagged from the search by twitter, we recommend that you contact them and ask why that is the case. In the meantime, you may use a JavaScript solution that will display your tweets from your feed.

Place the following code in your footer.php right above </body> tag.

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/wpbeginner.json?callback=twitterCallback2&count=5"></script>

Remember to change the username from wpbeginner to your username. Also you can change the count from 5 to whatever you like.

Then add the following HTML tags any where you want to display the recent tweets.

<div id="twitter_div"><ul id="twitter_update_list"><li>&nbsp;</li></ul></div>

You would need to edit the CSS file for proper styling.

Known Issues: This plugin does not have caching, so the scripts will be loaded every time the page loads.

Source: Twitter

Plugin

If you are one of the users who do not want to modify their theme files, there is an alternative plugin that you can use.

Alex King’s Twitter Tool

This plugin will let you display recent tweets from your account. It will store your tweets in the database to limit the API queries. Tweets are archived every 10 minutes.

Note: there are way too many plugins that do this, to list them all here.

Display Recent Tweets from Multiple Accounts

Display Recent Tweets from Multiple Accounts

Display recent tweets from Multiple accounts come can be useful to increase community interaction when you have a multi-author blog. You can spend hours on the web trying to find a good solution, but below are two best solutions that we found.

Tweet!

Tweet is an unobtrusive JavaScript plugin for jQuery that lets you put twitter on your website. This is a great snippet that loads the tweets using JSON. For the download and directions, you should visit the official page.

Known Issues: This script utilizes the Search API which has it’s limits. Your search query has a character limit set to 140 characters. So in short, you will be able to get a maximum of 6 – 8 users depending on the length of their username.

Tweet Blender

Tweet Blender Screenshot

Tweet Blender plugin allows you to display multiple user’s tweet. This plugin actually displays the tweets from user’s feeds, so it does not rely on the Search API. But the more names you put, the longer it will take to load.

Known Issues: None that we know of.

Integrate Twitter Conversations About Your Posts

People are talking about your posts, and their convesation is not limited to the comments in your post. A lot of that conversation is happening on Twitter. Why not bring this conversation right back to your blog?

Tweetback plugin imports those tweets about your posts as comments. You can display them in between the other comments on your blog, or display them separately.

You can also add widgets to your site that shows the “Most Tweeted Posts” and “Recently Tweeted Posts” with the use of a plugin called Tweet Stats . You must have the plugin (Tweetback that we mentioned above in order for this plugin to work).

Tweet Stat Widget Screenshot

Take your Blog communication to Twitter

Above we showed you how you can integrate twitter conversations about your blog posts into your comments. In this trick, you will give the user an ability to post the comment on your site, and then also have their conversation on twitter.

Commentwitter

This plugin will add a twitter login area below the comments, so users have an option to post their comment to twitter.

Post blog comments to Twitter

Display a Special Welcome Message for Your Twitter Users

Special Welcome Message for Your Twitter Users

There are some sites that display a special welcome message to their twitter users. This increase their chances of getting more followers and more retweets for that post.

Simply place the following code in your single.php file where you want the welcome message to be displayed.

<?php
if (strpos("twitter.com",$_SERVER[HTTP_REFERER])==0) {
echo "Welcome, Twitter User! If you enjoy this post, don't hesitate to retweet it to your followers";
}
?>

Display Your Twitter Friends on Your Site

Display Your Twitter Friends

You have seen the Facebook Fan page widget, Google Connect widget, and Mybloglog widget. All three of these display the friends/fans pictures. You can do that with twitter as well.

Twitter Friends Widget

This plugin displays your Twitter friends/followers in your sidebar in the same way that they appear on your Twitter homepage.

Twitter Profile Field in Comments

Twitter Field in Comments

Top tech sites are already doing this. If you go to Mashable or Tech Crunch, then you will see that they have an additional field below the Website URL for Twitter profile. There is a plugin that will let you do that fairly easily.

Twitter Link Comments

This plugin will add an extra field to your comment form so a user can add their Twitter username. A user configured ‘follow me’ link is then displayed along with their details on all their comments. The extra field and ‘follow me’ link can be configured using the settings page without ever needing to modify any template files. (unless you want to)

While these are some of the Most Wanted Twitter Hacks and Plugins, this list is definitely not the end of what you can do with twitter and WordPress. Infact there are 662 Results in the WordPress Plugin Directory when one runs the query for Twitter. There is also a list that we used as our source 107 Twitter Plugins for WordPress.

If you liked this post, then please retweet it, so others can also take advantage of this useful article. Also don’t forget to follow us on twitter.


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. Connor Crosby says:

    I tried to add the “special welcome message to twitter followers” but it is showing regardless of who it is. How can I fix that? I modified the code a little bit so I could include php and html inside it.

    Welcome, Twitter User! If you enjoy this post, don’t hesitate to retweet it to your followers

    • Connor Crosby says:

      Oops, it is displaying incorrectly, here it is:
      Welcome, Twitter User! If you enjoy this post, don’t hesitate to retweet it to your followers

    • Connor Crosby says:

      Ahh, it still shows wrong, another attempt:

      <?php if(strpos(“twitter.com”,$_SERVER[HTTP_REFERER])==0) { ?>
      <div>Welcome, Twitter User! If you enjoy this post, don’t hesitate to retweet it to your followers</div>
      <?php } ?>

  2. Li says:

    Does this script still work http://cdn.wpbeginner.com/blogpostsimages/wpandtwitter/singletweet.txt?

    I keep on getting “Something Must Have Gone Wrong…”

    • Editorial Staff says:

      There are better plugins out now… You can use the Simple Twitter Connect Plugin or seaofclouds jquery script. The singletweet script still works because we are using it on our client’s site.

  3. Tim Kaiser says:

    It’s a pretty good list. Nicely focused on Twitter. I have a few of these implemented and like the idea of allowing users to comment on my posts with their twitter id. Thanks!

  4. Ret says:

    Thanks for the complete and comprehensive list of twitter hacks and plugins. This is surely a golden post for every wordpress blogger like me. I found your article in the Google search page for the keywords “twitter script plugin for wordpress”.

  5. Dee Wilcox says:

    This post is great, thanks! I’m trying to display a single tweet on a page. Should I paste the snippet code into my functions.php file, or directly within the page itself? I just need the code to work on one page of the entire site.

    I appreciate your help!

  6. Mariah says:

    Hi! Excellent post! Congrats.
    I’m looking for a plugin to actualice multiple Twitter accounts. Any idea? Thanks a lot! ;)

  7. Jeff says:

    Dudes, this is good stuff, thanks.

    I tried this one:

    but the message shows regardless of where I come from, so if I just click on the post from my site I still see the welcome message. Is the code missing something?

    • Editorial Staff says:

      Are you talking about our site? or the code mentioned in this article. If you just place the referrer code it should work. On our site, it is on every page load, not referral base. You will see a different social media site that you can follow us on.

  8. Ritu Sharma says:

    Hmm… interesting post, thanks

  9. Hunter says:

    Great list with so many options it can be hard to choose one.

  10. Chris Roane says:

    I would recommend against using a plugin for any of these, if you are comfortable working with html. Your site will load faster.

    This is a great resource and if I want to add more twitter functionality to my site, I’ll definitely reference this. Thanks!

  11. Abban says:

    I embed latest tweets using simple xml and a preg replace to display the links: http://brightsky.ie/embedding-your-twitter-feed/

  12. Christopher says:

    Very useful tips, thanks for sharing!

  13. radixal says:

    information is very interesting, thanks for sharing

  14. Sandesh says:

    Awesome TuT. I am looking forward to add it on my page..TFS.

  15. Anything Graphic says:

    The second option with the Javascript worked though :-)

    Sorry for multiple comments. You rock WPb!

  16. Anything Graphic says:

    Tried the latest tweets and it gave me this error: Parse error: syntax error, unexpected T_STRING in line 44.

    Line 44 is: $cache_file = dirname(__FILE__).’/cache/’ . $usernames_for_file . ‘-twitter-cache’;

    :-(

    • Zhu says:

      Same here, I have a parse error when trying the latest tweets code. Any way to fix that? I’m not fluent in code, I’m not sure what’s wrong :lol:

      • Editorial Staff says:

        This code is working, we think that something was being removed when we were posting it on WPBeginner, so we put a .txt file where you can copy and paste the codes from. Try that and it should work. We have it working on a client’s website.

  17. Anything Graphic says:

    This is a fantastic posts. I have been wondering how to easily impliment my latest tweets. Pure GENIUS! Thank you. Off to experiment…

  18. Ozh says:

    Cool stuff, except that all the snippets using file_get_content(), well, suck. Function file_get_content() can be widely unavailable, and WP offers a much more reliable way to make HTTP request and fetch remote content (hint)

  19. Paul Murray says:

    Hmm… interesting, thanks :)

  20. Jake says:

    One WordPress hack I can’t wait to see is a Google Buzz widget with a live count of how many people have shared the link. I think Google can easily get this working with an official API

    • Editorial Staff says:

      Yes that one we would have to wait for. Even the Buzz share buttons are tricky. They are using Google Reader to update … Not the best option, but it is the only option for now.

  21. kruz says:

    Thx sharing. Use on my blog.

  22. Harsh Agrawal says:

    That’s a huge list and certainly I will integrate few of them. If not everyone, atleast twitter ID in comment field will be in the top priority list. :)

  23. jared thompson says:

    amazing collections of plugins and add-ons to use on any blog.

  24. Robert Chambers says:

    Thanks for sharing. A great overview of ways to integrate Twitter with WordPress. I’m already using a few of these on my blog, but I will be trying out some of the others.

  25. Rarst says:

    Sigh. As usual I must note that I only adapted my snippet from one by Joost de Valk of yoast.com :)

    By the way it looks like it got slightly broken when posting.

    • Editorial Staff says:

      Thanks for notifying about the issue. It is fixed.

      Btw: I have heard that statement before. While you did adapt it from Joost’s snippet about RSS Feeds, this was still your work. So you deserve the credit.

      I just want you to know that we truly appreciate your contributions.

      -Syed

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.