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.00002 sec (very fast) | 50000 times — 0.02 sec (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 5.7.1

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

From tag: Link (URL)

More from category: Helper Functions

No comments
    Log In