Random WordPress Function

Learn about a new WordPress function every day!


Function Signature:

wp_is_home_url_using_https

Function Description:

Checks whether the current site URL is using HTTPS.

Function Examples:

⚠️ Examples below are generated with GPT-3 once every hour. Do not take them too seriously.
Consider them as some extra input in your learning process - reason about them. Will it work? What could fail?
// Example 1: Check if the home URL is using HTTPS and perform an action based on the result
if ( wp_is_home_url_using_https() ) {
    // Home URL is using HTTPS, load secure assets
    wp_enqueue_script( 'secure-script', 'https://example.com/secure.js', array(), null, true );
} else {
    // Home URL is not using HTTPS, load regular assets
    wp_enqueue_script( 'regular-script', 'http://example.com/script.js', array(), null, true );
}
// Example 2: Redirect to HTTPS if the home URL is not already using it
if ( ! wp_is_home_url_using_https() ) {
    wp_redirect( set_url_scheme( home_url(), 'https' ) );
    exit;
}
// Example 3: Display a message to the user based on the home URL protocol
if ( wp_is_home_url_using_https() ) {
    echo 'You are browsing a secure connection.';
} else {
    echo 'Your connection is not secure, please be cautious.';
}