WpCode.net

Daily Wordpress Code Snippet

How to rewrite permalink automatically

| 0 comments

Pin It

Kevin Chard from Wpsnipp has written this great snippet (that i use too on wpcode so double thanks) that automatically rewrite article’s permalink.

This code exclude words with less than 4 letters and replace it with a “-”. This snippet improve your seo, you just need to paste the following code in a white line of your function.php file.

Thanks again Kevin Continue reading

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 Reply

Required fields are marked *.

*