wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Force specific pages to be secure, ssl, https

wordpress snippet

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.

snippet :  PHPcopy
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);

Did you like this post? If so please share it with your friends. Thanks!

  • GoWebBaby

    Thanks for this little but useful code lines.

  • http://www.facebook.com/miguelpalazzo Miguel Palazzo

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

    • http://wpsnipp.com Kevin Chard

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

  • Pingback: WordPress tip: Force specific pages to be SSL secure

  • Can Atasever

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

  • Peter

    Missing a ; after the return true :)

  • Pingback: Best WordPress snippets, hacks and tips from 2013 | CatsWhoCode.com

  • Pingback: 25 WordPress Code Snippets for Enhanced Performance - ManageWP

  • Sergio Pinna

    Weel done!

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

    Thank you! :-)

  • Brad Farnsworth

    Doesn’t work, all you did was add a filter, you did not apply it anywhere or trigger it.

    • http://wpsnipp.com Kevin Chard

      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,