Advertisement
swte

Overwrite script type (Swift Performance AI)

Jan 30th, 2023 (edited)
908
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. /**
  2.  * Filter for script type
  3.  * $type (string) can be swift/javascript or swift/lazyscript (swift/lazyscript will run only user interaction, while swift/javascript will be executed immediately after higher priority assets has been processed)
  4.  * $tag (Swift3_HTML_Tag) this is a Swift3 HTML Tag object, it has $attributes(array), $outer_html(string) and $inner_html(string) properties, what you can use to identify scripts
  5.  */
  6.  
  7. add_filter('swift3_script_type', function($type, $tag){
  8.     /// You can check src
  9.     if (isset($tag->attributes['src']) && preg_match('/REGEX_HERE/', $tag->attributes['src'])){
  10.         return 'swift/lazyscript';
  11.     }
  12.     /// You can check inner HTML
  13.     else if (preg_match('/REGEX_HERE/', $tag->inner_html)){
  14.         return 'swift/lazyscript';
  15.     }
  16.     return $type;
  17. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement