WordPress at a glance

wp_make_link_relative() WP 1.0

Convert full URL paths to absolute paths.

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.

✈ 1 time = 0.00002s = very fast | 50000 times = 0.02s = speed of light | PHP 7.1.5, WP 4.8

No Hooks.


String. Absolute path.


wp_make_link_relative( $link );
$link(string) (required)
Full URL path.


Since 2.1.0 Introduced.
Since 4.1.0 Support was added for relative URLs.

Code of wp make link relative: wp-includes/formatting.php WP 5.4.2

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

Related Functions

From tag: Link (URL)

More from category: Helper Functions

No comments
        Log In . Register