delay-js.php
1 year ago
delay-jswithjs.php
1 year ago
lazyload.js
3 years ago
lazyload.min.js
2 years ago
delay-jswithjs.php
15 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; // Exit if accessed directly. |
| 4 | } |
| 5 | |
| 6 | add_filter('cwvpsb_complete_html_after_dom_loaded','cwvpsb_load_js'); |
| 7 | function cwvpsb_load_js($content) { |
| 8 | $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 9 | $content = preg_replace('/<script(.*?)<\/script>/is', '<script type="cwvlazyloadscript" $1</script>', $content); |
| 10 | $pattern = '/<head[^>]*>/i'; |
| 11 | $lazyload_script = CWVPSB_PLUGIN_DIR."includes/javascript/lazyload{$min}.js"; |
| 12 | $lazyload_script = cwvpsb_read_file_contents($lazyload_script); |
| 13 | $content = preg_replace( $pattern, "$0<script id='cwvpsb-delayed-script'>{$lazyload_script}</script>", $content, 1 ); |
| 14 | return $content; |
| 15 | } |