Boost Your WordPress SEO with Short URLs

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:

https://wpmudev.com/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.

FREE EBOOK
Your step-by-step roadmap to a profitable web dev business. From landing more clients to scaling like crazy.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

FREE EBOOK
Plan, build, and launch your next WP site without a hitch. Our checklist makes the process easy and repeatable.

By downloading this ebook I consent to occasionally receive emails from WPMU DEV.
We keep your email 100% private and do not spam.

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.

{code type=php}
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:

{code type=php}

if (strlen($word) < 3) {

 

for this:

{code type=php}

if (strlen($word) < 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:

{code type=php}
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:

{code type=php}

$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: