Using a different CDN for script enqueuing

Some features in All in One SEO Pack require us to enqueue external dependencies through CDNs. You can dynamically filter the CDNs we rely on through the script_loader_src filter. Below you can find a demo code snippet that shows you how to use this filter. This can be useful if you’re operating from a country where certain CDNs are blocked.

 

add_filter( 'script_loader_src', 'aioseop_change_cdn_provider' );

function aioseop_change_cdn_provider( string $src ) {

   if( ! is_admin() ) {
      return;
   }

   if( preg_match('/.*cdn.jsdelivr.net.*/', $src ) ) {
      $src = 'https://cdnjs.cloudflare.com/ajax/libs/xregexp/3.2.0/xregexp-all.min.js';
   }


return $src;
}