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:
- Add this code to your theme’s functions.php file or in a site-specific plugin.
- 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.
Dosent do anything. This is crap.
[…] → Source: http://wpsnipp.com/index.php/functions-php/force-specific-pages-to-be-secure-ssl-https/ […]
Doesn’t work, all you did was add a filter, you did not apply it anywhere or trigger it.
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,
Your are right. It does not work. How it trigger for a page automatically .
Weel done!
But,what about login.php?
How can i use HTTPS at login page?
Thank you! 🙂
[…] Source […]
[…] Source: http://wpsnipp.com/index.php/functions-php/force-specific-pages… […]
Missing a ; after the return true 🙂
Thanks Kevin. What if we want to force 2 or more pages to be secure?
[…] to Kevin Chard for this […]
Can something similar be accomplished with specific sites on a WordPress multisite installation?
I’m sure it could, not something I have looked into though. Are these pages you are auto creating?
Thanks for this little but useful code lines.