How to Add HTTPS To All HTTP Internal Links Of A WordPress Post

There is a quick way to replace WordPress Internal HTTP links with HTTPS. In this article, I am showing you how to add HTTPS to all of the internal links of WordPress post content.

Lets Suppose we have a WordPress website. This website was either without any SSL certificate or for some strange reasons HTTPS internal links converted to HTTP internal links. These days, if you have internal links pointing to HTTP, it can affect your ranking badly in Google Search Results.

For whatever reason, either your website migrated from non-HTTP to HTTPS or moved from www. to non www protocol, your internal links are now HTTP. Here, I am writing a very simple code on how to change all the internal link inside posts from HTTP to HTTPS.

This change to make a secure URL is a peace of cake. In your functions.php file of your active theme, add below code:

// HTTPS To All Internal Links
function http_to_https_links_in_content($content)
{
  $content = str_replace('http://my-website-domain.com', 'https://my-website-domain.com',$content);
  return $content;
}
add_filter('the_content','http_to_https_links_in_content');

If you are worried that WordPress theme update will loose your code, dont worry, we can add the same code by creating a simple WordPress plugin with above few lines of code. Above code will replace all internal HTTP links to HTTPS internal links.