Connecting WordPress MU to Twitter to auto-tweet new blog posts

December 31st, 2007 by Dan York

twitter.pngGiven that over the past year Twitter has emerged as one of the new communication tools within social media, one of my natural reactions was to figure out how to connect this blog site to Twitter so that a post/tweet would appear in twitter.com/voxeo whenever we posted a new article. (If you are not aware of Twitter, my external “The 10 ways I learned to use Twitter in 2007” should give you an overview.) My main reason for wanting to do this was to provide another way for people to stay up on what we post here. For some people, myself included, it’s easier to follow someone on Twitter than even to subscribe to their RSS feeds. So I wanted to make it easy for someone to “follow” the posts we create here on blogs.voxeo.com.

My first instinct was to simply go over to Twitterfeed.com and set up a link between our RSS feed for all posts and our new Twitter account. This undoubtedly would have been the simplest path to go - and one I’d probably recommend for others. There were however, several problems/challenges/concerns:

  1. Twitterfeed.com requires the use of OpenID to login, which, as an OpenID advocate, I delight in. However, I wanted to create the feed using a Voxeo-related OpenID versus one of my own, so first I needed to go and turn this blog site into an OpenID provider.

  2. My second concern was just that Twitterfeed.com seemed somewhat inefficient in that it has to poll to find out if you had new posts to tweet. There’s naturally the potential time delay from posting… and also just the general inefficiency. We are not posting here all that often and don’t need the feeds checked all that much.

  3. My third concern was the issue of introducing yet another site in between this site and Twitter. Given Twitter’s API, it seemed logical that we could connect directly.

  4. By the time I got the site set up to provide OpenID, Twitter was experiencing some performance problems last Friday and the Twitterfeed.com site was also offline.

This last issue caused me to decide I had to solve the problem on our own server so that we aren’t dependent on another site.

A Google search brought me to the “Twitter Updater” plugin for WordPress which, on first glance, seemed to provide exactly what I was seeking. I followed the instructions, activated it for one of the blogs, filled in the credentials, posted a test post and……. nothing. No Twitter post. In further reading down the page, it became clear that the developer stopped further work on this plugin and in fact moved her blog from WordPress over to Drupal and so had no real interest in the plugin anymore. I tried a hack by another user, but it, too did not work.

Meanwhile a friend had recommended that I use Alex King’s great “Twitter Tools” plugin. I actually had it installed, but hadn’t really thought about it for purely posting to Twitter. The strength of the Twitter Tools plugin is really about taking your updates from Twitter and posting it to your blog (which the README clearly shows). However, in our case, we’re not going to be (or don’t expect to be, anyway) posting independently to twitter.com/voxeo. It’s just another publishing medium for us - a one-way publish out to the world of Twitter. So we don’t need to publish our tweets here because there won’t be any.

This is, however, the solution I ultimately used. I activated the plugin for one of the blogs on this site, configured it with our Twitter username and password and then changed the settings so that it was only publishing outbound to Twitter.

There was one change I did make to the PHP code. By default, every new blog post appears in your Twitter stream with the prefix “New blog post: “. However, since our Twitter stream is only new blog posts, this prefix is redundant and wastes some of our precious 140 characters! So I modified line 75 and 76 of “twitter-tools.php” from this:

$this->tweet_prefix = 'New blog post';
$this->tweet_format = $this->tweet_prefix.': %s %s';

to this:

$this->tweet_prefix = '';
$this->tweet_format = $this->tweet_prefix.'%s %s';

You can see the result now over on twitter.com/voxeo.

A couple of notes about this implementation:

  1. The good news is that this posts to Twitter as soon as we publish an article to a blog. No polling. No waiting. No reliance on a site in the middle (Twitterfeed). Just direct from our site to Twitter via the Twitter API.

  2. The good or bad news, depending upon your perspective, is that the plugin needs to be activated separately for each of your WPMU blogs. If you have a lot of WPMU blogs and all you want to do is take all the blog posts and post them to Twitter, you are probably far better off taking the Twitterfeed.com route and simply linking a site-wide RSS feed to a Twitter account. In our case, we don’t have a large number of blogs and while we anticipate adding a few more, we don’t expect to add a huge number. Activating/configuring this plugin is now something I’ll just add to my “provisioning checklist” when rolling out a new blog.

    Note that on the good news side, we do now have a much higher degree of control over precisely which blogs post to the Twitter.com/voxeo account. Because we have to manually configure it, we wind up having the flexibility to not configure certain blogs, so that their postings do not appear in the Twitter.com/voxeo stream. We also have the flexibility to configure a certain blog to post to a different Twitter account. That’s not something I see us doing, but we do now have the option, which we wouldn’t if we simply connected our “all blogs” RSS feed to a Twitter account.

  3. Do note that since we are using WordPress MU, after dropping the Twitter Tools plugin code into the “plugins” directory, I did need to go into the Site Admin page for the site and “allow” the use of the plugin for blogs on the site. After that, I could go into each individual blog, activate the plugin and then configure the settings.

  4. I have the plugin activated currently in four blogs and all are configured to post to the same Twitter account. Everything seems to be working fine.

So there it is… how I linked our WordPress MU blogs to Twitter to publish notifications to the Twitter account when we post new blog entries. Hopefully some of you out there will find this helpful.

Technorati Tags:
, , , , , , ,

Tags: , , ,

5 Responses to “Connecting WordPress MU to Twitter to auto-tweet new blog posts”

  1. Voxeo Talks » Blog Archive » Do you use Twitter? If so, you can now follow our blog posts… Says:

    [...] If you are interested, the gory details of what I did to connect our WordPress MU site to Twitter are available in our “Behind the Blog” weblog. [...]

  2. Me Says:

    Hi Dan, this article is good, I wondered if you have a problem with WPMU and the this plugin reposting already published posts when you edit the post as oppossed to only when they are published. them on your WPMU blogs?

    I thought I had solved the problem, but it wasn’t the case so I currently have the plugin disabled

  3. Dan York Says:

    You know, we just had this problem occur today. RJ went in to one of our older posts “Wanted: Routing Ninja” to fix the tags and when he saved the post, the Twitter feed was updated. He used the WPMU web interface to make the changes.

    However, I went into a blog post using (the offline editor) MarsEdit, updated it, sent in the edits and it did NOT cause that post to reappear in the Twitter stream. I just tried this again with another post. Opened it in MarsEdit, added a tag, and then hit “Send To Weblog”. Again, the updated older post did NOT appear in the Twitter stream. (However, *new* posts submitted via MarsEdit do trigger Twitter posts as you would expect they would.)

    So perhaps there is something with the plugin where it notices (and triggers on) updated posts that are edited via the web interface but does NOT notice/trigger on posts updated via the API.

    Curious. I’d love to know what you find out.

  4. Me Says:

    I know, I guess it’s valid to have your post update twitter, especially if you’ve added stuff to an older post, but I am one of those who has DOH! moments frequestly especially with brand new content so have to go back and fix it bam there goes another update. Perhaps I just need to be more diligent and proof better before publishing. Cheers

  5. techno matt » Even closer… Says:

    [...] to this post, I think I now have the silly prefix removed from the blog WordPress to Twitter [...]

Leave a Reply

Please note: By submitting a comment you agree to comply with our Comment Policy. We welcome all comments, positive or negative, but do reserve the right to remove all or part of blog comments that do not comply with our policy.