Languages: English • 日本語 (Add your language)
Checks if SSL is being used.
<?php is_ssl() ?>
This tag has no parameters.
<?php if (is_ssl()) { //action to take for page using SSL } ?>
Returns true if the page is using SSL (checks if HTTPS or on Port 443).
NB: this won't work for websites behind some load balancers, especially Network Solutions hosted websites. To bodgy up a fix, save this gist into the plugins folder and enable it. For details, read WordPress is_ssl() doesn’t work behind some load balancers.
Websites behind load balancers or reverse proxies that support HTTP_X_FORWARDED_PROTO can be fixed by adding the following code to the wp-config.php file, above the require_once call:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS'] = 'on';
Since: 2.6.0
is_ssl() is located in wp-includes/load.php
. For versions of WordPress prior to 4.6.0, it was located in wp-includes/functions.php
.