Skip to content

Commit

Permalink
Check async is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
puntope committed Aug 3, 2023
1 parent a57a604 commit f571294
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions includes/class-wc-google-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,13 @@ public function async_script_loader_tags( $tag, $handle, $src ) {
return $tag;
}

// Check if the script has the async attribute already. If so, don't add it again.
$has_async_tag = preg_match('/^.*async.*$/', $tag);

Check failure on line 726 in includes/class-wc-google-analytics.php

View workflow job for this annotation

GitHub Actions / PHP coding standards - diff

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 726 in includes/class-wc-google-analytics.php

View workflow job for this annotation

GitHub Actions / PHP coding standards - diff

Expected 1 spaces before closing parenthesis; 0 found
if ( ! empty( $has_async_tag ) ) {
return $tag;
}

// Add the async attribute
return str_replace( ' src', ' async src', $tag );
}
}

0 comments on commit f571294

Please sign in to comment.