X

How To Force Specific Pages to Be Secure by Using HTTPS and SSL

Snippets by IsItWP

Are you looking for a way to force specific pages to use HTTPS and SSL? This snippet will let you easily force specific pages in WordPress to be secure by using HTTPS and SSL.

Instructions:

  1. Add this code to your theme’s functions.php file or in a site-specific plugin.
  2. On line 2, specify the post or page ID as desired.
function wps_force_ssl( $force_ssl, $post_id = 0, $url = '' ) {
    if ( $post_id == 25 ) {
        return true
    }
    return $force_ssl;
}

add_filter('force_ssl' , 'wps_force_ssl', 10, 3);

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 6 Best WordPress Security Plugins Compared.

Comments   Leave a Reply

  1. Dosent do anything. This is crap.

  2. Amazing & fresh WordPress hacks | CatsWhoCode.com December 7, 2015 at 6:33 am
  3. Doesn’t work, all you did was add a filter, you did not apply it anywhere or trigger it.

    1. Hi Brad,
      This should work without issue, although it could be something specific you are trying to do. Can you provide more details about what you are trying to do,

    2. Your are right. It does not work. How it trigger for a page automatically .

  4. Weel done!

    But,what about login.php?
    How can i use HTTPS at login page?

    Thank you! 🙂

  5. 25 WordPress Code Snippets for Enhanced Performance - ManageWP April 9, 2014 at 11:20 am

    […] Source […]

  6. Best WordPress snippets, hacks and tips from 2013 | CatsWhoCode.com December 30, 2013 at 11:00 am
  7. Missing a ; after the return true 🙂

  8. Thanks Kevin. What if we want to force 2 or more pages to be secure?

  9. WordPress tip: Force specific pages to be SSL secure July 2, 2013 at 9:26 am

    […] to Kevin Chard for this […]

  10. Can something similar be accomplished with specific sites on a WordPress multisite installation?

    1. I’m sure it could, not something I have looked into though. Are these pages you are auto creating?

  11. Thanks for this little but useful code lines.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!