Ready to get started?Download WordPress


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

  1. jasontremblay
    Posted 9 months 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);



You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 9 months ago by jasontremblay
  • This topic is not resolved
  • WordPress version: 3.7.1


No tags yet.