Twitter Tools Hack

[Edit: Now that I have all of my widgets configured and things structured the way I want them, I discovered one or two flaws in what I originally posted — like mangled tweets in RSS feeds. I’ve included the revised tweak below the original.]

When I was looking for a good WordPress theme, I stumbled across Wu Wei by Jeff Ngan. It’s a beautiful theme he uses for his Equivocality site. What I loved about the home page was that he has a nice mix of blog posts and tweets — all complete with little twitter icons.

That triggered a Google search for something that would give me more powerful, but easy to use WordPress/Twitter integration. Twitter Tools is really packed with functionality, but there were just a few things that didn’t quite work the way I’d like them to. I really wanted the tweets in my blog to look like tweets.

I really like the way Twitter Blackbird Pie displays tweets, but that requires the tweet’s URL to be embedded in the post like this:!/twitter-user-name/twitter-status-id

A little digging through Twitter Tools code and changing a few lines of code, I now have a blog page that’s much closer to what I’m looking for.

If you’re using Twitter Tools to import your tweets to your blog, here’s how you can create a post that allows Twitter Blackbird Pie to display them the way your friends see them on Twitter:

Method #1:

  • Open /wp-content/plugins/twitter-tools/twitter-tools.php and find the do_tweet_post function.
  • The first line looks like this:
    global $wpdb;
    You’ll need to change that to this:
    global $wpdb, $aktt;
  • A few lines down, you’ll see another line of code that looks like this:
    'post_content' => $wpdb->escape(aktt_make_clickable($tweet->tw_text))
    You’ll want to change that one to:
    'post_content' => $wpdb->escape('!/' . $aktt->twitter_username . '/status/' . $tweet->tw_id)
  • That’s it. Save your changes and you’re done.

This method results in a nicely formatted single post, but the tweets in your RSS feed and main blog page will have a bit of gibberish because of the special tags that get rendered. The next method will address that issue.

Method #2

  • Complete all the steps outlined in method 1 above.
  • To have a nicely formatted main blog page, you’ll need to add another element to the data array to set the post’s excerpt:
    'post_excerpt' => $wpdb->escape('<img src="{twitter-icon-url}" /> <a href="!/' . $aktt->twitter_username . '/status/' . $tweet->tw_id . '">' . $tweet->tw_text . '</a>')
    Note: Either omit the twitter icon or replace {twitter-icon-url} with a full URL for the image you want to display on your tweets (example:

My next challenge is finding a way to turn the #hashtags in my tweets into post tags. Stay tuned!

Posted in articles, technology and tagged , .

Leave a Reply

Your email address will not be published. Required fields are marked *