-
-
Save tsarouxas/1da891da068502f3325ab4d2d52dab73 to your computer and use it in GitHub Desktop.
[WordPress][Simple Map] Load Google Maps API script from Simple Map deferred.
This file contains hidden or 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 | |
| defined( 'ABSPATH' ) or die( 'No direct access here.' ); | |
| /** | |
| * Plugin Name: Simple Map | Defer | |
| * Description: Makes sure Google Maps API script from <a href="https://wordpress.org/plugins/simple-map/">Simple Map</a> gets loaded deferred. | |
| * Author: Caspar Hübinger | |
| * Author URI: https://profiles.wordpress.org/glueckpress | |
| * Plugin URI: https://gist.github.com/glueckpress/56c88900aad391b95b5d44f4e752a1a4 | |
| * License: GNU General Public License v3 or later | |
| * License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
| */ | |
| /** | |
| * Make defer. | |
| * @link https://matthewhorne.me/defer-async-wordpress-scripts/ | |
| */ | |
| add_filter( 'script_loader_tag', function ( $tag, $handle ) { | |
| // Defer | |
| $defer_scripts = array( 'simplemap', 'google-maps-api' ); | |
| foreach( $defer_scripts as $defer_script ) { | |
| if ( $defer_script === $handle ) { | |
| return str_replace( ' src', ' defer="defer" src', $tag ); | |
| } | |
| } | |
| return $tag; | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment