Better SEO automatically remove short words from URL

Adding this snippet to the functions.php of your wordpress theme will automatically remove short words from the URL. This will remove words no larger then three characters long eg: in, and, but, is, etc…


I added an updated version of this snippet that uses stop words from a customizable list. This works better for most situations rather then arbitrarily removing words with three letters or less. Enjoy!

 

add_filter('sanitize_title', 'remove_short_words');
function remove_short_words($slug) {
if (!is_admin()) return $slug;
$slug = explode('-', $slug);
foreach ($slug as $k => $word) {
if (strlen($word) < 3) {
unset($slug[$k]);
}
}
return implode('-', $slug);
}

Leave a comment