Force Specific WordPress Pages to be Loaded With a SSL Secure HTTPS URL

httpsIf you have an SSL Security Certificate installed and setup on your Web Server so that you can access pages of your website through a Secure HTTPS URL then this code snippet might be very useful to you!

Many people prefer to only use the SSL Certificate to Secure pages that capture user data and in almost all cases, any page that captures a users Credit Card or other payment information, really any personal information that is transmitted should be secured. For several reasons we won’t get into here, sometimes you might not want every single page on a site to be HTTPS Secure and might only need certain pages. Like mentioned you might make a payment page that you want secure.

Let’s assume your payment page has a Page ID #123 in WordPress. With that information we can insert the code snippet below inside our Functions.php file or inside a custom site plugin, really can be loaded into any file that gets included into WordPress!

When this code is loaded on a page that matches the criteria we have set in the code snippet, it will then force that page/post to load over SSl with an HTTPS URL!

This is a great way to handle this situation in a WordPress site where you only need certain pages to use the SSL Certificate without relying on a Plugin.

PHP Code to Force Specific Pages to load with the SSL Certificate