WordPress

How To Force Use HTTPs instead Of HTTP For All Javascript Js File Or Stylesheet CSS Files In WordPress

Here we learn about how to force use HTTPs instead of HTTP for all Javascript js file or stylesheet CSS files in WordPress.

Custom code copied and paste into your child theme’s functions.php file.

<?php
add_action( 'wp_print_scripts', 'myblog_force_ssl_scripts', 100 );
add_action( 'wp_print_styles', 'myblog_force_ssl_styles', 100 );

function myblog_force_ssl_scripts(){
  if( !is_admin() ) {
    if( !empty( $_SERVER['HTTPS'] ) ){
      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 myblog_force_ssl_styles() {
  if( !is_admin() ){
    if ( !empty( $_SERVER['HTTPS'] ) ){
      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 );
      }
    }
  }
}
?>

 

Rahul Prajapat

I’m Rahul Prajapat. I’m a WordPress developer and Author at TheCodeHubs. I have good skill of Html, CSS, JQuery, SQL, Web API, PSD to HTML/PSD to WordPress, WordPress Theme/Plugin Customization, create or modify short code, customize visual composer short code or integrate new short code with visual composer, can create custom metabox for any post type in WordPress admin.

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago