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
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.
Further Reading on Blogging
- Blog conference in Indiana, mid-August
- Create reading list in WordPress from Amazon Wish List using Yahoo! Pipes
- SideBlog changes: remove titles, link post content
Further Reading on Current Events
- Blog conference in Indiana, mid-August
- bbPress: The forum from Automattic (makers of WordPress)
- Our agency profiled in local business journal
Further Reading on Productivity
- Create reading list in WordPress from Amazon Wish List using Yahoo! Pipes
- Recommended WordPress plugins
- Features and characteristics of a great 404 error page
Further Reading on Search Engine Optimization
- Recommended WordPress plugins
- Graphic web design and cascading style sheets
- Upgrading a blog to Wordpress 2.3 and changing your Ultimate Tag Warrior tags






April 10th, 2008 at 3:39 am
[...] Ignore direct tweets and SEO URLs with Twitter Tools WordPress Plug-in :: DesignWell :: Interactive … (tags: twitter hacks) [...]
June 19th, 2008 at 10:13 am
[...] 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, [...]
July 3rd, 2008 at 10:50 am
[...] 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! [...]
July 4th, 2008 at 5:01 pm
[...] 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 [...]