Title: wp_make_link_relative
Published: April 25, 2014
Last modified: May 20, 2026

---

# wp_make_link_relative( string $link ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#wp--skip-link--target)

Converts full URL paths to absolute paths.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#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.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#parameters)󠁿

 `$link`stringrequired

Full URL path.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#return)󠁿

 string Absolute path.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/formatting.php#L4834)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L4834-L4836)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#related)󠁿

| Used by | Description | 
| [_wp_normalize_relative_css_links()](https://developer.wordpress.org/reference/functions/_wp_normalize_relative_css_links/)`wp-includes/script-loader.php` |

Makes URLs relative to the WordPress installation.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.1.0](https://developer.wordpress.org/reference/since/4.1.0/) | Support was added for relative URLs. | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#comment-content-1377)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/wp_make_link_relative/#comment-1377)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-1377)
     Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-1377)
 4.  **Basic Example**
 5.      ```php
         <?php
         echo wp_make_link_relative( 'http://localhost/wp_test/sample-page/' );
         ?>
         ```
     
 6.  This should output the following URL:
 7.      ```php
         /wp_test/sample-page/
         ```
     
 8.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%3Freplytocom%3D1377%23feedback-editor-1377)
 9.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#comment-content-3435)
 10.   [arifktk](https://profiles.wordpress.org/arifktk/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/wp_make_link_relative/#comment-3435)
 11. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-3435)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-3435)
 12. **Example with Post ID:**
 13.     ```php
         echo wp_make_link_relative(get_permalink( $post->ID ));
         ```
     
 14. Where `$post` is your post object.
 15. **Example for current post:**
 16.     ```php
         echo wp_make_link_relative(get_permalink());
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%3Freplytocom%3D3435%23feedback-editor-3435)
 18.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/wp_make_link_relative/?output_format=md#comment-content-4833)
 19.   [Jake Jackson](https://profiles.wordpress.org/blue-liquid-designs/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/wp_make_link_relative/#comment-4833)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-4833)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%23comment-4833)
 21. Be aware that this function does not work as expected when a site uses a non-standard
     port.
 22.     ```php
         <?php
         echo wp_make_link_relative( 'http://localhost:8080/wp_test/sample-page/' );
         ?>
         ```
     
 23. will output
 24.     ```php
         :8080/wp_test/sample-page/
         ```
     
 25.  * In my test the output was `/wp_test/sample-page/`.
      * [Daniel Kossmann](https://profiles.wordpress.org/kossmann/) [5 years ago](https://developer.wordpress.org/reference/functions/wp_make_link_relative/#comment-5482)
 26.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F%3Freplytocom%3D4833%23feedback-editor-4833)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_make_link_relative%2F)
before being able to contribute a note or feedback.