Relative URL
[resolved] Request: Only Replace Local URLs (1 post)

  1. jasontremblay
    Posted 2 years ago #

    Suggestion: instead of filtering using the wp_make_link_relative function, perhaps you should add an intermediary filter function that first tests that links share the home url... I think that's the only time relative links make sense anyway. This seems to work:

    Note: I used an anonymous function that uses $home_url, to avoid problems when home_url itself was being filtered.

    $home_url = home_url();
    $filter_fn = function($link) use ($home_url) {
      if ( strpos($link, $home_url) === 0 ) {
        return wp_make_link_relative( $link );
      } else {
        return $link;
    foreach ( $filters as $filter ) {
      add_filter( $filter, $filter_fn);


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relative URL
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.