Created
May 6, 2018 07:28
-
-
Save tux255/e94690a1bc03dca40e583c72721b19cd to your computer and use it in GitHub Desktop.
Change Wordpress final output. LazyLoad integration for IMG tags. Not finished
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function callback($buffer) { | |
$patterns = [ | |
'/<img(.*) src=/', | |
'/<img(.*) class="/' | |
]; | |
$replacements = [ | |
'<img${1} data-src=', | |
'<img${1} class="b-lazy ' | |
]; | |
$buffer = preg_replace($patterns, $replacements, $buffer); | |
return $buffer; | |
} | |
function buffer_start() { | |
ob_start("callback"); | |
} | |
add_action('wp_head', 'buffer_start'); | |
function buffer_end() { | |
ob_end_flush(); | |
} | |
add_action('wp_footer', 'buffer_end'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment