WordPress.org

Forums

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

  1. jasontremblay
    Member
    Posted 1 year 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);
    }

    http://wordpress.org/plugins/relative-url/

Topic Closed

This topic has been closed to new replies.

About this Plugin

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

About this Topic

Tags

No tags yet.