Paul Roub

blah blah blahg

How to Exclude Replies From the Twitter Profile Widget

Should you (for some reason) visit the root page of roub.net, you’ll see a collection of posts from this blog, my work blog, Flickr photos, and other things, all collected by an aggregator named Planet Venus.

To keep the noise level down just a bit, I decided to keep my twitter activity out of that list, and use Twitter’s Profile Widget instead. It’s in the sidebar on that page.

That was still noisier than I wanted, though. I didn’t need my @replies to others showing up there, but the configuration options didn’t offer a “don’t include replies” choice. A bit of Googling led me to this page, which noted the code needed to add a filter, without explicitly showing where. Reading the widget code cleared that up, but it may be less than obvious if you don’t spend your days wrangling JSON.

The widget code that Twitter provides you with includes a block that starts with:

1
2
3
new TWTR.Widget({
  version: 2,
  ...

Look for the section below that which looks something like:

1
2
3
4
5
6
features: {
  scrollbar: false,
  loop: false,
  live: true,
  behavior: 'all'
}

The exact contents will vary. Leave them as is, and add, right after the features: line, the following:

1
2
3
filters: {
  negatives: /^@\w{1,20}\s/
},

The indentation doesn’t matter, but copy it verbatim otherwise. In the example above, we end up with:

1
2
3
4
5
6
7
8
9
features: {
  filters: {
    negatives: /^@\w{1,20}\s/
  },
  scrollbar: false,
  loop: false,
  live: true,
  behavior: 'all'
}

We’re telling the widget to remove any lines that start with a @ followed by 1-20 “word” characters. That is, anything starting with someone’s Twitter handle – a reply.

That’s it. Feel free to view the source at roub.net to see it in place.