wp_make_link_relative() WordPress Function

The wp_make_link_relative() function is used to convert a URL to a relative link. This is useful for making links relative to the current page or blog.

wp_make_link_relative( string $link ) #

Converts full URL paths to absolute paths.


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

$link

(string)(Required)Full URL path.


Top ↑

Return

(string) Absolute path.


Top ↑

Source

File: wp-includes/formatting.php

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


Top ↑

Changelog

Changelog
VersionDescription
4.1.0Support was added for relative URLs.
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More