Search code examples
phpwordpress

rewriting external links (WordPress)


I need to make photo hosting site external URL (http://ipic.su) to open over https protocol from my site. This photo hosting has both http and https versions, so sometimes my users post http links which causes mixed content warnings for users on my site.

I think this probably can be achieved by auto replacing http:// with https:// in URL using some function?


Solution

  • You can use the_content filter.

    E.g, a very simplistic approach:

    function ipic_to_https_filter($content) {
      $new_content = str_replace('http://ipic.su', 'https://ipic.su', $content);
      return $new_content;
    }
    
    add_filter( 'the_content', 'ipic_to_https_filter' );