Maybe this is all old hat to some, but I figured out what I think is a cool trick to get Twitter to serve as a quick means of sending specific updates to specific websites, and would like to share it with anyone who cares. You can see an example of it in action at http://voxhouse.net in the header (just below another fun API call which keeps track of my YouTube subscribers and total video view count).

Example of a website targeted tweet.

Now, there are plenty of nifty plugins out there for various CMS platforms which do the following: Grab tweets from a specified user and spit them out, or grabbing tweets containing a hashtag and spitting those out. The key to the usefulness of this lies in combining them, which requires a bit of lateral thinking.

Meaning normally, these would be done using different types of queries altogether. If you wanted to return tweets by the user HenrikRyosa, the call would appear something like this:

http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=HenrikRyosa&count=3

This would return the last 3 tweets of the user. A query for a hashtag, on the other hand, would normally use the search method:

http://search.twitter.com/search.rss?q=%23somerandomhashtag

The problem inherent with simply checking for a specific hashtag, as many plugins do already, is that when someone loads your page, it will return tweets from any user which is using that hash, whether it’s actually relevant to your site or not. This can lead to confusion, and worse, it opens your site up to trolls, spam, or worse.

For example if someone wanted to, they could insert a link to a malicious website inside a tweet, add your hashtag, and voila: Your website would now be quite undesirably sharing harmful links which your users would click and then blame you for!

With the method I will outline briefly here, you will be able to ensure that tweets appearing on your sites are both from you, as well as being only the tweets you wish to show up. This comes in handy if, for example you are a “jack of all trades” type of person such as myself, who wants, oh, I don’t know, say design related tweets only to show up on their design website, and not their random been-up-for-30-hours-and-thinks-everything-is-super-funny quips or celebrity jokes.

Twitter + WordPress = Win

This should work with pretty much any method which uses the Twitter search query API, and will assume that you have the skills to at least change a simple line of PHP code where the API call is made. For my purposes, I use the Twitter Feed plugin for WordPress by Alex Moss, which at this time does not support this feature but who knows, perhaps he’ll catch wind of this and add it but nevertheless, you may very well use another plugin or method of querying the API for your own feed.

The Twitter Feed plugin uses a shortcode, which can be placed inside posts, pages and widgets in WordPress, in my case I created my own dynamic widget area which looks snazzy in the header area of my site and provides a quick view of whatever latest tidbits I want to share with my users. The shortcode allows for a number of variables such as twitter username, and the mode that it should use to query the API.

By going into the plugin editor, you can find the line where it describes the standard hashtag query:

if ($mode == "hashtag") { $twitter_rss = "http://search.twitter.com/search.rss?q=%23".$hashtag."&rpp=".$num; }

with some simple changes, (or you could even create a new “mode” if you like) you can make it check that the source of the tweet is the username specified in the shortcode you’ll be using:

if ($mode == "hashtag") { $twitter_rss = "http://search.twitter.com/search.rss?q=from%3A".$username."+%23".$hashtag."&rpp=".$num; }

The addition, specifically of from%3A”.$username.”+ to the code is needed. Or if you want to make it easier and don’t anticipate needing to ever change the username, you could make it something like from%3AHenrikRyosa+ – where the %3A represents an URL encoded colon.

Finally, the shortcode itself would appear something like:

[twitter-feed username="henrikryosa" num="1" followlink="no" mode="hashtag" hashtag="vxhs"]

Now if I wanted to absolutely maximize my tweetable real estate, given that I’m limited to 140 characters, I could make the hashtag as simple as #v and it would work just as well – it doesn’t really matter whether the hashtag means anything to others to serve its purpose – although it may be discouraged to do so. I chose #vxhs in my case because it represents “voxhouse” uniquely while being short enough for most purposes.

Happy twittering!