From 294aafe6e577d3ff4174a29d4085d2c72ba43649 Mon Sep 17 00:00:00 2001 From: Pedro Reis Date: Fri, 28 Feb 2020 10:18:44 +0000 Subject: [PATCH] Update functions.php --- functions.php | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/functions.php b/functions.php index 9bbb56c..382ba06 100755 --- a/functions.php +++ b/functions.php @@ -77,6 +77,90 @@ function barebones_enqueue_scripts() { add_action( 'wp_enqueue_scripts', 'barebones_enqueue_scripts' ); +/** + * Add async and defer attributes to enqueued scripts + * + * @param string $tag + * @param string $handle + * @param string $src + * @return void + */ + +function defer_scripts( $tag, $handle, $src ) { + + // The handles of the enqueued scripts we want to defer + $defer_scripts = [ + 'SCRIPT_ID' + ]; + + // Find scripts in array and defer + if ( in_array( $handle, $defer_scripts ) ) { + return '' . "\n"; + } + + return $tag; +} + +add_filter( 'script_loader_tag', 'defer_scripts', 10, 3 ); + + +/** + * Add custom scripts to head + * + * @return string + */ + +function add_gtag_to_head() { + + // Check is staging environment + if ( strpos( get_bloginfo( 'url' ), '.test' ) !== false ) return + + // Google Analytics + $tracking_code = 'UA-*********-1'; + + ?> + + + +