Shorter Twitter Sidebar Links

Note: This post is over a year old. You may want to check later in this blog to see if there is new information.

A quick note for people using Twitter and Wordpress. You’ve probably noticed that nasty problem I was having where the twitter sidebar links were overlapping the blog’s main text on the front page when twitter failed to tinyurl the link. Well, I fixed it…

I use Alex King’s Twitter Tools, heavily customized, to display the sidebar. It’s a wonderfully devised, database driven way of collecting and caching twitter updates that isn’t dependent upon direct API access at the time of page load. I use 2 parts of the plugin, the post notification part, and the sidebar part. I’ve modified the sidebar pretty heavily to create my fade and change the terminology. Now I’ve added a function that just strips out all the link text and replaces it with [link]. To accomplish this, I just added a breaklinks function:

breaklinks function

< ?php
function breaklinks($content) {
	$pattern = '/(<a[^>]*>)(.*)(< /a>)/i';
	$replacement = ' [${1}link${3}] ';
	$content = preg_replace($pattern, $replacement, $content);
	return $content;
}
?>

This is called right before the text is displayed in the sidebar, after it’s been made clickable and special characters have been removed. It will just take any links it finds, and replace the text between the [a] tags with the word link. This makes for much shorter entries and stops the unwrapped, lengthy urls from breaking my layout.

» » » » »
  1. brett 06.03.07 / 10am

    If you use this code, please note that one of my plugins is causing problems with the code display. There is an extra space before the /a in the pattern line that should be a backslash.

  2. Alex 06.05.07 / 12pm

    FYI - Twitter Tools (at least in SVN) supports the WP Chunk plugin (which shortens URLs) if you have it installed.

  3. brett 06.05.07 / 12pm

    I’ll have to check that out, thanks!

Have your say

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Safari hates me