WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp make link relative

Description

Convert full URL paths to relative 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.

Usage

<?php wp_make_link_relative$link ?>

Parameters

$link
(string) (required) Full URL path.
Default: None

Return Values

(string) 
Absolute path.

Examples

Default usage

<?php
echo wp_make_link_relative('http://localhost/wp_test/sample-page/');
?>

This should output the following URL:

/wp_test/sample-page/

Notes

Change Log

Since: 2.1.0

Source File

wp_make_link_relative() is located in wp-includes/formatting.php.

Related

See also index of Function Reference and index of Template Tags.