Friday, June 5, 2009

Update: WordPress - Modifying Post Content

Earlier in May I wrote up this post about modifying WordPress post content and prefixing URIs to go through a tracker. Well, one of the web designers here found this ridiculously rare bug. Apparently if you have content that has a URI that breaks at the end of a line because of word wrap, the trackURL function will not process. Weird!

So, I tested and confirmed and basically rewrote the entire function to one line. Who knew?

Anyhow here it is in all of its glory:

function trackURL($content) {
$content = preg_replace('/\< a(\s|\n|[^href])href=\"([^"]+)\"\>([^<]+)\<\/a\>/','$3',$content);
return $content;
}


Blogger is giving me gripe about the regex, so here's a screenshot:


Cheers!

No comments: