Should You Use Relative Internal Links in WordPress?
Relative internal links in WordPress may seem attractive - but there are hidden landmines that you need to watch out for.

On this page
Every now and then, an idea comes along that seems good, but when you think about it a little more, the flaws become apparent. This happened when I thought of moving my CDN to something other than Cloudflare, but then the disadvantages became suddenly apparent once I tried it. But there are other, more disruptive ideas that can explode in your face, and it’s best to know the advantages and disadvantages before jumping in. Relative URLs are one such example.
#Why Consider Relative URLs?
A relative URL is one that doesn’t contain the domain name – just the part afterward. When a browser encounters such a URL, it assumes that it belongs to the same domain on which it’s hosted, and treats it as such. So instead of entering:
www.xyz.com/test
You would write instead:
/test
The first is an “absolute” URL, and the second is a “relative” URL. You can add the following code to your WordPress functions.php to ensure that the internal link selector inserts relative URLs, and not absolute ones:
function make_relative( $url, $post, $leavename ) {
if ( $post->post_type == 'post' ) {
$url = wp_make_link_relative($url);
}
return $url;
}
add_filter( 'post_link', 'make_relative', 10, 3 );
To learn how to insert code like this in WordPress, see this earlier tutorial on how to do it. Once you’ve added this code, you can bring up the internal link editor like this:

Select the post you want that’s already on your site, and it should enter a relative links as shown here:

So why would you want to do this?
Really the only reason I can see for this to make sense, is if you’re thinking of changing domain names one day and need to seamlessly transfer your site and for all URLs to work out of the box. But that reason seems very forced, since you can just do a “search and replace” directly in the database if necessary.
#What About SEO? What Does Google Think of Internal Links?
As always before any change, we have to bow before the mighty Google and get their opinion. As of now, the official word is that Google doesn’t care if the links are relative or absolute as evidenced by this tweet:
But apart from this, there are some very good reasons NOT to use internal links, and stick to absolute ones instead.
#1. Risk of Multiple Versions of Website
Website URLs can be written in a variety of ways:
example.com
www.example.com
https://example.com
https://www.example.com
etc…
Ideally, all versions of a website should redirect to ONE single canonical URL. Decide the format of your URLs, and then stick to it rigorously afterward.
But if your relative URLs redirect to another version of the URL, you could end up with multiple versions of the same content on different URLs, which could be disastrous in a number of ways. It’s not entirely clear how Google treats this kind of duplicate content, but it’s very bad form for a site and could have significant SEO issues, up to and including Google penalties.
#2. Easier for Others to Steal your Content
With absolute URLs, a hacker has to put in more work to duplicate your website. They need to manually rewrite all your absolute URLs to point to their own site. Relative URLs on the other hand, make their work much easier. All they need to do is copy your site structure, and they’re done!
Web spammers are a lazy bunch. You’ll be surprised at how often simple precautions are enough to stop the majority of attacks!
#Bottom Line: Absolute URLs are the Best
There’s no substitute for absolute URLs, and ones that all redirect to a single “perfect” URL. Here’s an earlier tutorial on the efficient way to redirect all incorrect URLs to one that has HTTPS and “www”. So if you’re toying with the idea of relative URLs, make sure you know exactly what you’re doing. Otherwise, the consequences could be severe!




