wp_make_link_relative( string $link )

Convert full URL paths to absolute paths.


Description Description

Removes the http or https protocols and the domain. Keeps the path ‘/’ at the beginning, so it isn’t a true relative link, but from the web root base.


Top ↑

Parameters Parameters

$link

(string) (Required) Full URL path.


Top ↑

Return Return

(string) Absolute path.


Top ↑

Source Source

File: wp-includes/formatting.php

function wp_make_link_relative( $link ) {
	return preg_replace( '|^(https?:)?//[^/]+(/?.*)|i', '$2', $link );
}

Top ↑

Changelog Changelog

Changelog
Version Description
4.1.0 Support was added for relative URLs.
2.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.