Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Filter for script type
- * $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)
- * $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
- */
- add_filter('swift3_script_type', function($type, $tag){
- /// You can check src
- if (isset($tag->attributes['src']) && preg_match('/REGEX_HERE/', $tag->attributes['src'])){
- return 'swift/lazyscript';
- }
- /// You can check inner HTML
- else if (preg_match('/REGEX_HERE/', $tag->inner_html)){
- return 'swift/lazyscript';
- }
- return $type;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement