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.

  • Since 4.1.0 Support was added for relative URLs.
✈ 1 time = 0.00002s = very fast | 50000 times = 0.02s = speed of light PHP 7.1.5, WP 4.8

No Hooks.

Return

String. Absolute path.

Usage

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

Code of wp_make_link_relative: wp-includes/formatting.php VER 4.9.8

<?php
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
    Hello, !     Log In . Register