WordPress Plugin Customization: Twitter Tools
Jun. 29, 2009 · 14 Comments
Tweeting is nice because it’s terse; I can update my tweeps about what I’m doing, resources I’ve discovered and articles I’ve read between more lengthy and media-rich blog posts (and to publicize those posts).
The Twitter Tools plugin is a great way to integrate tweets into a WordPress blog. The most obvious benefit of this is that it keeps the content on the blog page fresh and allows bloggers to communicate bitlets of information that do not require their own post.
In addition to other worthwhile features, Twitter Tools allows a blog admin to display recent tweets in a sidebar widget, and to automatically publish tweets in a daily or weekly digest format. Twitter Tools caches tweets in a table of the WordPress database to reduce the number of calls to Twitter.
There were a few things about the plugin I didn’t particularly like out of the box. First, there was a link below the last tweet in the sidebar widget to take a visitor to my Twitter page. I prefer to have the widget title be that link. Second, the digest post title date format was ugly: “2009-06-29″ instead of “June 29, 2009″. Third, the link at the end of each tweet in the digest post had a simple ‘#’ instead of the date and time of the tweet, which also serves as a link to the original tweet.
To fix the first problem all I had to do was modify the title variable of the aktt_widget function. aktt_profile_url($aktt->twitter_username) returns the URL of my Twitter updates. $aktt->twitter_username holds is the username set in the plugin options. It would have been simpler to hard code my Twitter URL here, but that would have rendered the modified plugin importable, which is a major programming faux pas. This modification does ignore the title set in the plugin options.
function aktt_widget($args) { global $aktt; extract($args); $options = get_option('aktt_widget'); $title = '@<a href="'.aktt_profile_url($aktt->twitter_username).'">'.$aktt->twitter_username.'</a> on Twitter'; if (empty($title)) { } echo $before_widget . $before_title . $title . $after_title; aktt_sidebar_tweets(); echo $after_widget; }
To hide the “More updates…” link at the bottom of the sidebar widget I simply commented out the code which adds it.
/*if (!empty($aktt->twitter_username)) {
$output .= ' <li class="aktt_more_updates"><a href="'.aktt_profile_url($aktt->twitter_username).'">More updates...</a></li>'."\n";
}*/To fix the date format in the title of digest posts I simply found the array key which holds the post title and modified its value. Voila!
$post_data = array( 'post_content' => $wpdb->escape($content), 'post_title' => $wpdb->escape(sprintf($title, date('F j, Y'))), 'post_date' => date('Y-m-d H:i:s', $end), 'post_category' => array($this->blog_post_category), 'post_status' => 'publish', 'post_author' => $wpdb->escape($this->blog_post_author) );
The third problem was the most troublesome, but still pretty simple. Why the plugin developer chose to use a hash mark (#) instead of the date and time of the tweet as a link to the actual tweet is curious to me. The hash is not only not informative, but used to indicate keywords in tweets, which can be confusing.
Twitter Weekly Updates for May 24, 2009
There are certainly positive aspects of hot weather. RT @ccmaine: Today’s weather is begging for a sundress and [high heels] :) #
What is the date and time of the tweet above? This modification adds valuable information while preserving the ability to click on a hyperlink to visit the original tweet.
Twitter Weekly Updates for June 28, 2009
Excellent ideas to get creative juices flowing! RT @problogger: 100 Creative Twitter Backgrounds Featuring Illustration – http://is.gd/1fZCW 27 Jun 2009 @ 08:27
This is all done in a switch statement of the aktt_tweet_display function.
switch ($time) { case 'relative': $time_display = aktt_relativeTime($tweet->tw_created_at, 3); break; case 'absolute': $time_display = aktt_absoluteTime($tweet->tw_created_at); break; }
The value of the time_display variable was originally a boring '#'!
I borrowed code from the aktt_relativeTime function to write aktt_absoluteTime.
function aktt_absoluteTime ($date) { $time = gmmktime( substr($date, 11, 2) , substr($date, 14, 2) , substr($date, 17, 2) , substr($date, 5, 2) , substr($date, 8, 2) , substr($date, 0, 4) ); return date('j M Y @ H:i', $time); }
This simply takes the tweet time as a parameter and returns a formatted date string. Not too bad, eh?
Next I’ll have to modify the plugin to make mentions clickable. Or I can wait for the update, which will wipe out my customizations. :)
development · php · plugin · programming · social networking · twitter · wordpress

SHERYL · 20090916 at 22:50
Can you change the formatting of Twitter Tools… I would love to frame the box that houses my tweets and have each tweet in it’s own framed box…..
Admin comment by Brent Danley · 20090917 at 20:33
Hi, Sheryl. Yes! Anything can be changed, since you have access to the code. Your solution is to modify the CSS.
Kim Lewis · 20090925 at 08:33
Hey Brent, above you stated that your solution to changing the appearence is modifying the CSS. What i want to do is change the left padding of the actual tweets (class=”aktt_tweets”) but can’t seem to find this class anywhere in the twitter-tools/twitter-tools.php file. My test environment is here: http://kim.synapticate.com/. Could you shed any light on how to change this margin? Thanks in advance!
Jen · 20090929 at 17:25
Were the changes for the date and from “#” to username for the tweets listed as a blog and not the widget? Not a pro at coding – want to make sure. Thanks
Admin comment by Brent Danley · 20090930 at 08:03
Kim,
The
$outputvariable is constructed beginning at line 761 (version 2.0) of twitter-tools.php (function aktt_sidebar_tweets()). You are correct that the class is aktt_tweets.To set the padding/margin in the CSS just create a selector in your theme’s CSS file (style.css).
I hope this helps.
Jen,
Yes, in the digest posts. My modifications were overwritten when I recently upgraded the plugin. I’m doing a major retheme and will rewrite my Twitter Tools modifications when that is complete.
jxj · 20100221 at 01:55
Thanks for sharing. The code of the date part is exactly what I am looking for.
Phillip James · 20100503 at 10:54
Hi,
Would you know if it’s possible to alter the title of the blog post that is automatically created from my tweets?
Eg. instead of the post title being a shortened version of the tweet I could make the title for every post ‘via twitter’.
Thanks,
Phil.
Admin comment by Brent Danley · 20100503 at 23:11
Phil, I’m not sure exactly what you mean by post title. Are you having Twitter Tools create a blog post whenever you tweet?
Phillip James · 20100504 at 02:13
Hi Brent,
Yeah.
I use my http://www.twitter.com/HUMMatTheBird account to to tweet.
That tweet will then appear at http://hummatthebird.com/wednesdays/ as a blog post.
Though I would like the title of the posts created to automatically say ‘via twitter’ instead of a snipped of the actual tweeted message.
The site is in complete test phase though am just testing functionality.
Thanks.
Admin comment by Brent Danley · 20100504 at 21:40
Just change the
'post_title'value in thedo_tweet_postfunction.Phillip James · 20100507 at 05:35
Found that, thanks.
Though not be too experienced with PHP I’ve added
, ‘post_title’ => print ‘via Twitter’
and the title now comes through as ’1′
Probably missing another simple thing…hah.
Admin comment by Brent Danley · 20100507 at 06:50
The post_title line should be:
, 'post-title' => 'via Twitter'Tammi · 20100711 at 21:15
Newbie here…
Do I place those codes into custom.css?
or…
I haven’t found a Twitter PlugIn that I liked yet, but this one sounds great!
And, is there a way to change the link colors?
Thanks,
Tammi
Admin comment by Brent Danley · 20100712 at 07:55
Unfortunately, Tammi, no. You’d have to modify the plugin, which would mean future updates would break your customization. You can easily change the colors, though. Just add a class selector in your CSS file. The div has class “aktt_tweets.”
Let me know if you require additional explanation. I’m happy to help.