WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/is ssl

Contents

Description

Checks if SSL is being used.

Usage

<?php is_ssl() ?>

Parameters

This tag has no parameters.

Return Values

(bool) 
Returns true or false

Examples

<?php 
  if (is_ssl()) {
    //action to take for page using SSL
  }
?>

Notes

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

Change Log

Since: 2.6.0

Source File

is_ssl() is located in wp-includes/functions.php.

Related

force_ssl_admin()

force_ssl_content()

Administration_Over_SSL

See also index of Function Reference and index of Template Tags.