Adding HTTPS To All Internal Links Of A WordPress Posts

Here in this post, I am going to show you how to add HTTPS to all of the internal links of WordPress posts.

Suppose there is a WordPress site. The site was without any SSL certificate and it contains HTTP URL. It can be found that after moving a non-HTTPS WordPress site to HTTPS the internal links of your other posts still contains HTTP.

It is clear that the internal links of the posts do not update on a WordPress site after the site get SSL. So I am going to tell you how to change all the internal link inside posts from non-HTTPS to HTTPS.

Well, it is very easy to do it. In your functions.php file of the theme, just add the following code:

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

The above code also can be written by creating a separate plugin and adding the above few lines of code inside the plugin’s file. It will automatically replace your existing internal links inside posts which are non-HTTPS.

The code snippets you have got from this post may be so useful to you. In many times, it can be found that a WordPress site owner gets SSL for a WordPress site and after enabling SSL, all the internal links still remains without HTTPS.



Leave a Reply

Your email address will not be published. Required fields are marked *