wp_make_link_relative

Convert full URL paths to absolute paths.

Description

(string) wp_make_link_relative( (string) $link ); 

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.

Returns (string)

Absolute path.

Parameters (1)

0. $link (string)
Full URL path.

Usage

  1. if ( !function_exists( 'wp_make_link_relative' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // Full URL path. 
  5. $link = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_make_link_relative($link); 
  9.  

Defined (1)

The function is defined in the following location(s).

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