Change how Twitter Tools Formats Your WordPress Blog Post Tweet

In: Web Authoring

18 May 2009

Alex King’s Twitter Tools Plugin is a must if you are a WordPress Blogger and Twitter user. It’s most compelling feature is that it can automatically post a Tweet when you post a new blog post. This also works for time delayed posts, it Tweets when the post is published. One of the things I didn’t like about it was that it prefixed every blog post with “New Blog Post: “ which is a sure fire way to make sure more than half your followers don’t click it.

The thing is, you have already said what you want to say in your title hopefully, so how about we just Tweet the title and a link? Changing this code comes with one dire warning, you have to keep something in the prefix, that’s how the plugin finds Tweets to create the digest post, so instead of “New Blog Post: “, I am going to change mine to just “BP “.

Editing The Code

There is one class in the source code that defines the settings you can’t change in the UI, that class is called “twitter_tools.” Lines 18-27 define UI items, and 29-36 are supposed to not be end user editable, but we aren’t going to let that stop us.

   1:  class twitter_tools {
   2:      function twitter_tools() {
   3:          $this->options = array(
   4:              'twitter_username'
   5:              , 'twitter_password'
   6:              , 'create_blog_posts'
   7:              , 'create_digest'
   8:              , 'digest_title'
   9:              , 'blog_post_category'
  10:              , 'notify_twitter'
  11:              , 'sidebar_tweet_count'
  12:              , 'tweet_from_sidebar'
  13:              , 'give_tt_credit'
  14:              , 'last_tweet_download'
  15:              , 'doing_tweet_download'
  16:              , 'doing_digest_post'
  17:          );
  18:          $this->twitter_username = '';
  19:          $this->twitter_password = '';
  20:          $this->create_blog_posts = '0';
  21:          $this->create_digest = '0';
  22:          $this->digest_title = __("Twitter Updates for %s", 'twitter-tools');
  23:          $this->blog_post_category = '1';
  24:          $this->notify_twitter = '0';
  25:          $this->sidebar_tweet_count = '3';
  26:          $this->tweet_from_sidebar = '1';
  27:          $this->give_tt_credit = '1';
  28:          // not included in options
  29:          $this->update_hash = '';
  30:          $this->tweet_prefix = 'New blog post';
  31:          $this->tweet_format = $this->tweet_prefix.': %s %s';
  32:          $this->last_digest_post = '';
  33:          $this->last_tweet_download = '';
  34:          $this->doing_tweet_download = '0';
  35:          $this->doing_digest_post = '0';
  36:          $this->version = '1.0';
  37:      }

Lines 30 and 31 are what we are concerned with. Line 30 defines the Tweet Prefix. On my blog I changed this to just ‘BP’ to shorten it and get me back some characters. Line 31 defines the format string for the post, I also wanted to get rid of the colon, so I changed it to read:

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

That’s it, now when your blog publishes, it will post a Tweet that’s a bit more concise and looks more like you wrote it rather than an automation.

7 Responses to Change how Twitter Tools Formats Your WordPress Blog Post Tweet

Avatar

Nate

July 22nd, 2009 at 3:13 pm

Jason, I like using Alex King’s Twitter Tools plugin as well, and I’ve already customized the Tweet prefix to something more appropriate for my use than “New Blog Post:” but what I’ve been trying to figure out how to do is for the prefix to be the name of the category that the new blog post resides in.

For example, when you added this blog post, it would tweet the prefix “Web Authoring: “. My PHP isn’t great and I’m struggling with it. Got any ideas?

Avatar

Jason Burns

July 22nd, 2009 at 3:54 pm

You could probably easily change the prefix to display the $_post(‘category’) which holds the information you seek, but there is one huge flaw in that plan. Alex’s TwitterTools uses the prefix to find tweets and filter them out all over the plugin, also to make sure it doesn’t retweet something you have already sent when you update or edit a post. So my suggestion might be leave the prefix alone, then post the category AFTER the prefix or the post itself, something like “PK: New Blog Post in Technology”

My 2 cents :)

Avatar

Nate

July 23rd, 2009 at 7:56 am

Thanks for the tip, and the warning. That makes more sense. I’ll play around with it, and hope my site doesn’t enter the ‘spinning fireball of death’ Alex warns of.

Avatar

Victor

August 11th, 2009 at 1:29 pm

I’ve a problem with the twitter tool. When I publish a post it appear on twitter but there’s no link to the post.
Please help me,
Victor

Avatar

Woth

October 16th, 2009 at 2:44 am

to victor… check the ID Key of the short URL you are using in the plugin. It has a weird blanck space at the end!!

Avatar

Craig

October 26th, 2009 at 5:33 pm

Thanks for the tip about $_post(’category’). I was wondering if you could elucidate a little about how to implement that. I want to modify my tweets so that they are formatted like so:

New PARENTCATEGORY: TITLE (LINK)

I fiddled around with the code a little, but I’m not too savvy with all this and I had to undo my changes. Thanks in advance for any help you can give!

Avatar

Carol Shepherd

January 20th, 2010 at 10:32 am

I’m looking for a solution the other way around: I’d like WordPress to take the tweet and add a prefix to it. Does anyone know if there’s a way to do that?

Carol Shepherd
arborlaw.biz

Comment Form

About this blog

Jason Burns is a technology enthusiast, Microsoft guy, photographer, musician and all around geek. This blog is the general rambling one, check out the links for the specific ones!

Photostream

    Dean VMNT SignatureESP VB.C. Rich VJackson King VMean Water HoseMean Water HoseMean Water HoseNew House - Lived in a littleNew House - Lived in a little
Jason Burns

Create Your Badge