Home / functions.php / Force specific pages to be secure, ssl, https
  • How to Force specific pages to be secure, ssl, https


    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.

    wordpress snippet : PHP

    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);

    ( WordPress codex functions, hooks, in this snippet. )

    add_filter, wp,
  • 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,

    • S M Abu Sayeed

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