Boost Your WordPress SEO with Short URLs

Paying attention to your SEO can mean the difference between ranking high on Google or being exiled to the search engine wastelands (i.e. your website may as well not exist at all).

One of the easiest ways to improve your SEO is to think smarter before hitting “publish” on your posts. When the all-seeing Google indexes your website and decides which sites to prioritise over others, one of the factors it takes into consideration is your post’s URL, or permalink.

So it makes sense to summarize your content into an awesome URL. But how do you do that?

By keeping your URLs tight – and using the handy snippets of PHP code below.

WordPress SEO

Google’s head of search spam Matt Cutts says it all about keeping your URLs short and sweet:

“If you have got a three, four or five words in your URL, that can be perfectly normal. As it gets a little longer, then it starts to look a little worse. Now, our algorithms typically will just weight those words less and just not give you as much credit.

“The thing to be aware of is, ask yourself: ‘How does this look to a regular user?’ – because if, at any time, somebody comes to your page or, maybe, a competitor does a search and finds 15 words all strung together like variants of the same word, then that does look like spam, and they often will send a spam report. Then somebody will go” and check that out.

When you publish a post, the title usually becomes the slug, which is the part of a URL that identifies a page using human-readable keywords. And that slug becomes part of the post’s permalink, just like the URL for this post with the slug in bold:

http://premium.wpmudev.org/blog/boost-wordpress-seo-with-short-urls/

While this slug is six words long, it is descriptive, includes keywords (WordPress, SEO, URLs) and isn’t excessively long.

Often, it’s easy to forget about the slug and hit publish without giving your URL a second thought. So to help you out, here’s a handy snippet that will help you keep your permalinks tight.

Adding the code below to the functions.php file of your WordPress theme will automatically remove short words from the URL. This includes all words that are shorter than three characters, such as: a, it, I, by, of etc.

1
2
3
4
5
6
7
8
9
10
11
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);
}

If you want to want to remove three-letter words, such as and, the and for, you can do so by swapping this line of code:

1
if (strlen($word) &lt; 3) {

for this:

1
if (strlen($word) &lt; 4) {

However, you might want to take things a step further. You can specify specific words you don’t want in your permalinks by adding the following code to your functions.php file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
add_filter('sanitize_title', 'remove_false_words');
function remove_false_words($slug) {
if (!is_admin()) return $slug;
$slug = explode('-', $slug);
foreach ($slug as $k => $word) {
//false words list separated for commas
$keys_false = 'a,about,above,across,after,again,against,all,almost,alone,along,already,also';
$keys = explode(',', $keys_false);
foreach ($keys as $l => $wordfalse) {
if ($word==$wordfalse) {
unset($slug[$k]);
}
}
}
return implode('-', $slug);
}

To add words to the banned list, edit this line of code:

1
$keys_false = 'a,about,above,across,after,again,against,all,almost,alone,along,already,also';

Thanks to Kevin Chard for these awesome snippets.

Do you use short URLs on your site or are you guilty of neglecting it? Tell us in the comments below.

Image credits: chase_elliott.

Tags ,

Comments (10)

  1. when i start a new blog i change perfences from blog setting to short url address, of course your article nice because most of bloggers don’t know how to change functions php but we can use blog settings or using plugins for that.Thanks.

Participate