-
-
Save Roshanb54/15ab4673b00a8573b0082f7561082ef0 to your computer and use it in GitHub Desktop.
Append async to wp_enqueue_script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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