Posted Post

Posted People, Posted Life.

Hack WordPress "sanitize_title" Function

I use English as title only, recently I noticed some of my blog post has “%” in url (e.g.) or too too many dashes “—” in url (e.g.). !!!!! (2008/6/23 .. forget this method, check Ultimate WP Post Name URL Sanitize Solution)

So unacceptable. So I check the wordpress code and update the following:

function sanitize_title($title, $fallback_title = ”) {
$title = strip_tags($title);
$title = preg_replace(’/&.+?;/’, ”, $title); // Kill entities
$title = preg_replace(”/[^a-z0-9]+/i”, ” “, strtolower($title)); // Remove all non-english and non-number code
$title = trim(preg_replace(”/ {2,}/i”, ” “, $title)); // Remove extra space
$title = apply_filters(’sanitize_title’, $title);
if (empty($title)) {
$title = $fallback_title;
}
return $title;
}

at “formatting.php”.

Next thing: I serious think about shorter very long url (the post_name is varchar(200) in database)

Possibly related posts: (automatically generated)
Hack WordPress "sanitize_title" Function

1 Comment »

  Pat wrote @ June 20th, 2009 at 2:56 AM

Awesome. Worked Well. :D

Your comment

HTML-Tags:
<a href="" title=""> <abbr title=""> <img alt="" align="" border="" height="" hspace="" longdesc="" vspace="" src="" width=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Alexa CounterFeedBurner Counter