Skip to content

WordPress Plugin – ABT Relative URLs

Here’s a WordPress plugin that will help you transfer your site across domains by stripping out the default “absolute url” from post content with a relative “/”; note that this works as you create content, so it should be the first plugin you install!

Download ABT Relative Urls  Download from WordPress

As taken from the readme file:


By default, WP inserts absolute urls into post content; this includes the protocol and domain, which is based on the home Admin setting. This plugin replace all self-referencing (domain) links with relative paths “/” instead. Works when inserting images into posts, and on the actual save_post action it scrubs the contentexcerpt, and post_meta fields.

Especially helpful when developing on a DEV site with the intention of transfering to a LIVE domain. Please note that you should use this plugin before you start adding content, or you’ll have to resave everything later.

Includes code based on Relative Image URLs plugin, which strips domain when inserting images from the Media Library. A similar idea to Absolute to Relative URLs, but works automatically, and handles meta fields.


  1. Unzip, upload plugin folder to your plugins directory (/content/plugins/)
  2. Activate plugin
  3. Create content – view HTML source to ensure that domains have been stripped from content.

Frequently Asked Questions

How does it work?

First, it determines the absolute URL from the admin settings (home key, via home_url()), as this is what WordPress uses when hardcoding links.

On save_post action, it examines both the post_content and post_excerpt submissions and strips the current domain/protocol from:

  1. href attributes
  2. src attributes
  3. all other instances of the domain

It then retrieves all of the postmeta, scans through the array, and removes the domain from any values. Since it’s a direct dump, it maybe_unserializes each value before recursively scrubbing the content.

Can I use the absolute URL?

Yes with protected shortcode:

[abt_absolute_url trailing="/suffix/"] 

where the attribute trailing is optional, and would append whatever is given to the absolute url. Really it’s just provided as a “just-in-case”, as you could write [abt_absolute_url]/suffix/ just the same.

Can I change what’s replaced?

By default, the following:

array( 'src="' . $absolute_path_prefix , 'href="' . $absolute_path_prefix , esc_attr( $absolute_path_prefix ) ) 

are replaced with

array( 'src="' . $relative_path_prefix , 'href="' . $relative_path_prefix , esc_attr( $relative_path_prefix ) ) 

Two hooks are provided to alter these defaults:

  • abt_relative_urls_get_search_for: the first “search” array
  • abt_relative_urls_get_replace_with: the second “replace” array

The reason it looks for the src, then href, then the actual attribute has to do with compatibility with the included relative image url plugin.


Check out our other developer-centric plugin, WP-Dev-Library. Suggestions/improvements welcome!

The Atlantic BT Manifesto

The Ultimate Guide To Planning A Complex Web Project


Atlantic BT's Insights

We’re sharing the latest concepts in tech, design, and software development. Learn more about our findings.

Questions & Answers

Are there differences in application architecture that are important for the cloud?
It is important to build applications and workloads specifically for the cloud. You will want to carefully consider what services the cloud provider of your choice has to offer and how your application leverages those services.
Learn More about Are there differences in application architecture that are important for the cloud?
Are there any drawbacks to cloud hosting?
Yes, there will always be some risks associated with any hosting option. You are relying on the resiliency and engineering of infrastructure that has scaled at an astounding rate.
Learn More about Are there any drawbacks to cloud hosting?
What’s the benefit of hosting in the cloud vs. traditional options?
Reasons not to host in the cloud are few and far between. If you don't host in the cloud, you will spend more in both CapEx and OpEx to manage your applications or websites in a traditional environment.
Learn More about What’s the benefit of hosting in the cloud vs. traditional options?
How can I improve the performance of my application?
There are several primary reasons that applications perform poorly, and in some cases it’s a combination of several. 1) Data latency: If your application is making calls to a data source (whether it’s an API or a direct call) and there is latency at the data provider, your application performance will suffer.
Learn More about How can I improve the performance of my application?
Should I move my application to the cloud?
The answer is ‘probably yes’. There aren’t many reasons for an application to be hosted elsewhere, aside from occasional compliance standards, or requirements to integrate with local services that would require large amounts of data to move from on-premise to cloud.
Learn More about Should I move my application to the cloud?
Where should my application be hosted?
There are many different options for hosting, but most applications would do well with one of the cloud providers -- Amazon Web Services, Google Cloud Platform, Microsoft Azure.
Learn More about Where should my application be hosted?