X

Force specific pages to be secure, ssl, https

Athena Review - slide options

You can easily force specific pages to be secure in wordpress using the following simple little snippet. Just add the following snippet to the functions.php of your wordpress theme and specify the post / page ID 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);

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!