Security PHP Beginner

Force HTTPS for the Login Page and wp-admin

Make WordPress always use HTTPS for logins and the dashboard, so passwords and cookies are never sent unencrypted.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
wp-config.php 1 lines
define( 'FORCE_SSL_ADMIN', true );

Where to add this

Recommended wp-config.php Above the line that says "That's all, stop editing!" in your wp-config.php file.

If your site has an SSL certificate, logins and admin pages should never load over plain HTTP. This one line makes WordPress redirect wp-login.php and wp-admin to HTTPS and send login cookies only over secure connections.

How it works

FORCE_SSL_ADMIN tells WordPress to use HTTPS for every admin and login URL it creates, and to redirect any HTTP request for them. Login cookies are then marked secure, so the browser never sends them over an unencrypted connection.

Things to watch

  • Your certificate must be working first. Visit https://yoursite.com/wp-admin/ before adding this.
  • Behind a load balancer or Cloudflare’s Flexible SSL, WordPress may not see the connection as secure and could redirect forever. Use Full SSL, or tell WordPress about the forwarded protocol in wp-config.php.
  • For the front end, set your site addresses to https:// in Settings → General.

How to test it

Visit http://yoursite.com/wp-login.php. You should be redirected to the https:// version.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only