Skip to content

Instantly share code, notes, and snippets.

@AntonLitvin
Forked from vishalbasnet23/functions.php
Created February 8, 2019 20:29
Show Gist options
  • Save AntonLitvin/98683f8ea373f75541b17ed9baf78bb9 to your computer and use it in GitHub Desktop.
Save AntonLitvin/98683f8ea373f75541b17ed9baf78bb9 to your computer and use it in GitHub Desktop.
Append async to wp_enqueue_script
<?php
function advanced_asyc_scripts($url) {
if ( strpos( $url, '#asyncload') === false ) {
return $url;
} else if ( is_admin() ) {
return str_replace( '#asyncload', '', $url );
} else {
return str_replace( '#asyncload', '', $url )."' async='async' defer='defer";
}
}
add_filter( 'clean_url', 'advanced_asyc_scripts', 11, 1 );
add_action( 'wp_enqueue_scripts', 'the_outdoor_trip_enqueue_scripts' );
function the_outdoor_trip_enqueue_scripts() {
wp_enqueue_script( 'google-map', 'https://maps.googleapis.com/maps/api/js?key=AIzaSyA2I2cP6UiavrQHrhZBk_jVKhFsr1qYln0#asyncload', array('jquery'), '3', true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment