Ignore reply tweets and SEO URLs with Twitter Tools WordPress Plug-in

It’s been a hot debate over what to include in your blog’s RSS recently. I say you should include more than blog posts in your RSS feed IF (and this is a big if) you can editorialize what goes in. The following, explains how to change which tweets from Twitter get posted to your blog and into your RSS feed.

If you use Alex King’s Twitter Tools (version: 1.1b1), you will want to make the following two changes to his code. The first one will make your tweet-post URLs and title more beautiful and SEO friendly by not splitting words at the end. The second one will remove reply tweets (’@username’) from becoming posts in your blog, so that half-conversations do not get recorded.

In Alex King’s purpose, Twitter Tools is an archiving tool that saves tweets into his blog. If you use version: 1.2b1, then Twitter Tools can hide reply tweets (those beginning with ‘@’) from displaying in the Twitter Tools sidebar widget, but it will still save every tweet as a blog post. In my purpose of Twitter Tools, I do not want to save (and thus post) tweets that begin with ‘@.’ Therefore you will still need to add the additions to the do_tweet_post function below. If you do not, all tweets will end up in your RSS feed as blog posts.

Let’s not mince words here

If you link your tweets and publish them in your RSS feed, you may have noticed that Twitter Tools trims tweets at 30 characters and usually cuts off a title mid-word. It would be better to index to the previous space and trim the post-slug there. Replacing the code of the function, trim_add_elipsis (at about line 1030 in twitter-tools.php, before function ak_gmmktime()) with the code that follows will do this:

if (!function_exists('trim_add_elipsis')) {
// smjdesign edit begin - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function trim_add_elipsis($string, $limit = 100) {
// shorten string
$string = substr($string, 0, $limit);
//find last space character
$max_char_pos = strrpos($string, ' ');
// shorten to last space and add ellipsis
if ($max_char_pos > 0)    { $string = substr($string, 0, $max_char_pos)."..."; }
return $string;
}
// smjdesign edit end - - - - - - - - - - - - - - - - - - - - - - - - - - - -

As a bonus, I’ll tell you were you can change the length of the title, too. It’s around line 205 within the do_tweet_post function. Look for a ‘30′ at the end of a line containing “trim_add_elipsis” Change the ‘30′ to something larger, for instance 40 or 50.

When indirect communication is preferred

UPDATE: Alex has made ignoring reply tweets (beginning with ‘@’) a standard option within Twitter Tools. However, I still recommend changing the trim size as I mention above.

I can’t imagine using Twitter Tools without the following change. If not made, one will be listing half conversations in their blog. In order to ignore direct tweets (or more specifically tweets that start with ‘@’), edit the following code at the end of the do_tweet_post function (at about line 215 in twitter-tools.php):

function do_tweet_post($tweet) {
global $wpdb;
remove_action('publish_post', 'aktt_notify_twitter');
$data = array(
'post_content' => $wpdb->escape(aktt_make_clickable($tweet->tw_text))
// smjdesign edit begin - - - - - - - - - - - - - - - - - - - - - - - - - - - -
, 'post_title' => $wpdb->escape(trim_add_elipsis($tweet->tw_text, 40))
// smjdesign edit end - - - - - - - - - - - - - - - - - - - - - - - - - - - -
, 'post_date' => get_date_from_gmt(date('Y-m-d H:i:s', $tweet->tw_created_at))
, 'post_category' => array($this->blog_post_category)
, 'post_status' => 'publish'
, 'post_author' => $wpdb->escape($this->blog_post_author)
);
// smjdesign edit begin - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if(substr($data["post_content"], 0, 1) != '@') {
$post_id = wp_insert_post($data);
add_post_meta($post_id, 'aktt_twitter_id', $tweet->tw_id, true);
wp_set_post_tags($post_id, $this->blog_post_tags);
}
// smjdesign edit end - - - - - - - - - - - - - - - - - - - - - - - - - - - -
add_action('publish_post', 'aktt_notify_twitter');
}

As always, you can email me from the contact page and ask me for the entire PHP file if you do not feel comfortable editing the file yourself.

If you have found this post valuable, please share it with others: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Facebook
  • del.icio.us
  • Google
  • StumbleUpon
  • TwitThis

A note about the author

Photograph of Stephen JamesMedia designer with experience in interactive, print and video. I have a marketing and advertising agency background and currently work full-time at a full-service agency. Visit my contact page, even if you would just like to say hello. To stay in touch, follow me on Twitter or connect on a variety of other social networks. Thanks for stopping by!

5 Responses to “Ignore reply tweets and SEO URLs with Twitter Tools WordPress Plug-in”

  1. links for 2008-04-10 | Shawn's Thoughts Says:

    [...] Ignore direct tweets and SEO URLs with Twitter Tools WordPress Plug-in :: DesignWell :: Interactive … (tags: twitter hacks) [...]

  2. SideBlog changes: remove titles, link post content :: DesignWell :: Interactive media tutorials and tips Says:

    [...] you already know, I post all my non-reply tweets from Twitter on my personal blog with Twitter Tools. I do not display the posts with the Twitter Tools widget, [...]

  3. Recommended WordPress plugins :: DesignWell :: Interactive media tutorials and tips Says:

    [...] is used with SideBlog in the sidebar of RachelandStephen. I have a tutorial on how I prefer to use Twitter Tools in my sidebar. Further Reading on BloggingCreate reading list in WordPress from Amazon Wish List using Yahoo! [...]

  4. eclecticism » Blog Archive » Links for July 1st through July 4th Says:

    [...] Ignore reply tweets and SEO URLs with Twitter Tools WordPress Plug-in: If you use Alex King’s Twitter Tools, you will want to make the following changes to his code. The first one beautifies your tweet-post URLs by not splitting words at the end. The second keeps reply tweets (’@username’) from becoming posts in your b [...]

  5. Why I took Twitter of Friendfeed | IRC Freak Says:

    [...] googling around its obviously possible to create a feed that would parse out replies (This post details how to do it for twitter tools), but I have neither the time or skill to work out a way to [...]

Leave a Reply


My Sites