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);
}
}
}
}
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
Post a Comment