How to force use https insted of http for all javascript js file or stylesheet css files in wordpress

Just copy and paste below code into your theme's functions.php file

add_action('wp_print_scripts', 'rj_force_ssl_scripts', 100);
add_action('wp_print_styles', 'rj_force_ssl_styles', 100);


function rj_force_ssl_scripts() {
    if (!is_admin()) {
        if (!empty($_SERVER['HTTPS'])) // or you can also use is_ssl() function for check ssl
        {
            global $wp_scripts;
            foreach ((array) $wp_scripts->registered as $script) {
                if (stripos($script->src, 'http://', 0) !== FALSE)
                    $script->src = str_replace('http://', 'https://', $script->src);
            }
        }
    }
}


function rj_force_ssl_styles() {
    if (!is_admin()) {
        if (!empty($_SERVER['HTTPS'])) // or you can also use is_ssl() function for check ssl
        {
            global $wp_styles;
            foreach ((array) $wp_styles->registered as $script) {
                if (stripos($script->src, 'http://', 0) !== FALSE)
                    $script->src = str_replace('http://', 'https://', $script->src);
            }
        }
    }
}

Comments

Popular posts from this blog

How to add image option in nav menu in wordpress

How to add a custom email functionality in woocommerce,wordpress for example new email template for shipping order

How to change user id on checkout page for assign order to different user in woocommerce wordpress