lized fired just before making LazyLoad global // so next execution cycle have it $on_initialized_javascript_wrapped = 'window.addEventListener("LazyLoad::Initialized", function(){' . 'setTimeout(function() {' . $on_initialized_javascript . '}, 1);' . '});'; } $embed_script = '' . ''; $buffer = preg_replace( '~]*)*>~Ui', '\\0' . $embed_script, $buffer, 1 ); // load lazyload in footer to make sure DOM is ready at the moment of initialization $footer_script = '' . ''; $buffer = preg_replace( '~]*)*>~Ui', $footer_script . '\\0', $buffer, 1 ); } elseif ( $method == 'inline_footer' ) { $footer_script = '' . ''; $buffer = preg_replace( '~]*)*>~Ui', $footer_script . '\\0', $buffer, 1 ); } else { // 'sync_head' $head_script = '' . ''; $buffer = preg_replace( '~]*)*>~Ui', '\\0' . $head_script, $buffer, 1 ); $footer_script = ''; $buffer = preg_replace( '~]*)*>~Ui', $footer_script . '\\0', $buffer, 1 ); } return $buffer; } public function wp_get_attachment_url( $url, $post_id ) { $this->posts_by_url[$url] = $post_id; return $url; } private function metaslider_hooks() { add_filter( 'metaslider_nivo_slider_get_html', array( $this, 'metaslider_nivo_slider_get_html' ) ); } public function metaslider_nivo_slider_get_html( $content ) { // nivo slider use "src" attr of tags to populate // own image via JS, i.e. cant be replaced by lazyloading $content = preg_replace( '~(\s+)(class=)([\"\'])(.*?)([\"\'])~', '$1$2$3$4 no-lazy$5', $content ); return $content; } }