WordPress: Automatically Remove Short Words In URL For Better SEO

WordPress: Automatically Remove Short Words In URL For Better SEO

According to Matt Cutts's answer in his interview at Pubcon, for good SEO, the URL should contains 3-5 words. If there are more than 5 words, Google's algorithms typically will just weight those words less and just not give you as much credit. So, we should keep our URL as short as possible, and remove all unwanted words.

Usually the short words in URL (with number of character not greater than 3) are not very good for SEO, and they often contain stop words like 'a', 'an', 'the', etc. They should be removed from the URL for better SEO. In WordPress, we can do it automatically without any plugin.

Just paste the following code into your functions.php file of your theme:

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);
}

The function remove_short_words will hook into sanitize_title action. It takes the post slug as an argument, explode its words into an array. Then it check length of every element, if length < 3 then remove it. You can change 3 to any number of characters, but I think 3 is a good choice.

Now try to create a new post. Type the title and see it in action. For example, if I type in the title field: 'This is a sample post', then I'll get 'this-sample-post' as post slug (URL). This is quite good, isn't it?

Hope this small tip can help you improve your SEO score of your blog and get better position in SERPs.

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO