Plugin / Absolute Relative URLs

Andrew Patterson

Installation

Installation

  1. In WordPress go to Plugins->Add New and locate the plugin (e.g. search ‘absolute relative url’
  2. Click the install button
  3. Activate the plugin through the ‘Plugins’ menu

That’s it! Check your database after you’ve saved some content. URLs should be root relative. Check your editor. URLs should be absolute. Check the source on your web page. URLs should be absolute.

The plugin does not retroactively modify urls in your database unless you manually update content. However, it can convert urls as needed. See notes about related sites.

Should you stop using the plugin your website will still work as the plugin uses root relative urls and browsers assume the same domain when they see a relative url. Exceptions would be when a you are running in a subdirectory and that is part of your site url, if you are providing an RSS feed to third parties where absolute urls are required, or if you use the multi-site conversion.

  • New in version 1.6.0

With the introduction of the WordPress block editor, urls were not being converted to absolute urls when editing content. They were converted properly when viewing content on the front end, and that is where it is important. But for consistency, and to meet the intent of the plugin, you now see absolute urls in the block editor. This is enabled by default. You can disable it with the following code in your functions.php:

// disable conversion to absolute urls when editing using the block editor
add_filter( 'of_absolute_relative_urls_use_block_editor', function() { return false; } );

A new feature in this version is the ability to remove and restore the ‘sites/’ part of the upload path when running in a multi-site environment. Unlike url conversions, where most websites will continue to display appropriately when you deactivate this plugin, this feature requires this plugin to be active in order to restore the sites part of the upload path. On the other hand, you should be able to move a stand alone site into a multi-site environment and let this plugin insert the sites part of the upload path without having to convert your database. To enable this feature, add the following filter to your functions.php:

// enable multi-site feature for upload path
add_filter( 'of_absolute_relative_urls_parse_sites_path', function() { return true; } );

Tested plugin in a multi-site environment and confirmed that conversion of urls, except for the sites part of the upload path, work as expected. In a multi-domain environment, the domain is removed and restored. In a multi-folder environment, the domain and folder are removed and restored. This is the same as running stand-alone with a domain only, or in a folder within a domain.

Another feature introduced in this version is the ability to disable the conversion to absolute or relative urls. There are other wordpress plugins that convert to relative urls, but don’t offer the complement. Disable the conversion to absolute urls and you have the same functionality. Or should you want to revert back to having absolute urls stored in the database, disable relative urls, then edit and save content to restore the full urls to your database. To disable one or the other, add one of the following to your functions.php:

// disable absolute url conversion on your website
add_filter( 'of_absolute_relative_urls_enable_absolute', function() { return false; } );

// disable relative url conversion on your website
add_filter( 'of_absolute_relative_urls_enable_relative', function() { return false; } );

What may be the most poweful new feature is the ability to display your site under your current domain, even when it was created under a different domain, without doing any conversion. That’s right. We’ve enhanced the related sites feature to do real time conversion from existing content, not just new content. You can now migate one domain to another, add a related site for the former domain, and enable related sites for existing content. To do this last bit, add the following to your functions.php:

// enable related sites feature for existing content
add_filter( 'of_absolute_relative_urls_enable_related_sites_existing_content', function() { return true; } );

When you set up related sites, and the site url and wordpress url are the same, you can now specify either one. For example, either of the following will work:

// add a related site using 'site url'
add_filter( 'of_absolute_relative_urls_related_sites',
    function( $related_sites ) {
        $related_sites[]['url'] = "http://apatterson.org/site2";
        return $related_sites;
    }
);
// add a related site using 'wordpress url'
add_filter( 'of_absolute_relative_urls_related_sites',
    function( $related_sites ) {
        $related_sites[]['wpurl'] = "http://site2.apatterson.org";
        return $related_sites;
    }
);

One more thing. We now parse ‘data-link’ urls along with others such as ‘href’ and ‘src’. We discovered these being used in the gallery component of the block editor.

  • New in version 1.5.4

Allow urls from related sites to be saved as relative urls. This makes it easier to copy/paste html content from one site to another (e.g. staging to production, production to development). Note that this doesn’t solve all problems with copy/paste from one site to another. For example, if images on one site are in a different folder, they will still need to be tweaked manually.

To add related sites, add a filter and function to your functions.php similar to the following:

// add related sites to be saved as relative urls
add_filter( 'of_absolute_relative_urls_related_sites', 'my_related_sites' );
function my_related_sites( $related_sites ) {
    $related_sites[] = [
        'wpurl' => 'https://www.chennabaree.com', // wp url
        'url' => 'https://www.chennabaree.com' // site url
    ];
    $related_sites[] = [
        'wpurl' => 'https://www.schoolofunusualarts.com'
    ];
    return $related_sites;
}

Note: if site url and wp url are identical, you only need to specify ‘wpurl’.

  • New in version 1.5.0, 1.5.1

Enable all options instead of specific options. In functions.php, put:

// enable all options
add_filter( 'of_absolute_relative_urls_enable_all', function() { return true; } );

Manage filters that get processed by modifying the array of filters. Build a function to add or remove filter names in the array. Then in functions.php, put:

// modify list of filters to include or exclude
add_filter( 'of_absolute_relative_urls_{type}_filters', 'your_function' );

where {type} is ‘view’, ‘save’, ‘option’ or ‘exclude_option’.

Ratings

5
3 reviews

Rating breakdown

Details Information

Version

1.6.0

First Released

11 Mar, 2016

Total Downloads

13,307

Wordpress Version

4.4.0 or higher

Tested up to:

5.1.3

Require PHP Version:

-

Tags

Contributors

Languages

The plugin hasn't been transalated in any language other than English.

DIRECTORY DISCLAIMER

The information provided in this THEME/PLUGIN DIRECTORY is made available for information purposes only, and intended to serve as a resource to enable visitors to select a relevant theme or plugin. wpSocket gives no warranty of any kind, express or implied with regard to the information, including without limitation any warranty that the particular theme or plugin that you select is qualified on your situation.

The information in the individual theme or plugin displayed in the Directory is provided by the owners and contributors themselves. wpSocket gives no warranty as to the accuracy of the information and will not be liable to you for any loss or damage suffered by you as a consequence of your reliance on the information.

Links to respective sites are offered to assist in accessing additional information. The links may be outdated or broken. Connect to outside sites at your own risk. The Theme/Plugin Directory does not endorse the content or accuracy of any listing or external website.

While information is made available, no guarantee is given that the details provided are correct, complete or up-to-date.

wpSocket is not related to the theme or plugin, and also not responsible and expressly disclaims all liability for, damages of any kind, arising out of the use, reference to, or reliance on, any information or business listed throughout our site.

Keep Leading Your Followers!
Share it for them.