Skip to content

Instantly share code, notes, and snippets.

@Roshanb54
Forked from vishalbasnet23/functions.php
Created May 16, 2017 04:24
Show Gist options
  • Save Roshanb54/15ab4673b00a8573b0082f7561082ef0 to your computer and use it in GitHub Desktop.
Save Roshanb54/15ab4673b00a8573b0082f7561082ef0 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