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.

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

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

  2. [...] 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. [...] 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. [...] 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. [...] 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 [...]

  6. Shawn says:

    I like your approach.

    Any suggestions on how to add a prefix to the post_title within Twitter Tools? I’d like the title for my tweets to be appended with something like “Twitter Feed” when they appear in WP.

  7. In version 1.5b3, I’d recommend editing the array $post_data['post_title'] within the function do_tweet_post() around line 415. This will edit the post title.

  8. [...] Interactive Llama has their own solution for that involving cutting the title as usual but then, if spaces actually exist, it will cut it a little more at the last space (that means that the half word will be removed and only the last whole word should remain). [...]

  9. wapexp is one of the rare marketing firm that offers best among rest SEO, WEB DEVELOPMENT, WEB DESIGNING internet marketing company , we pay back your trust in a manner that no one can do.

Leave a Reply