Skip to content

Instantly share code, notes, and snippets.

@solymosi
Created September 7, 2014 08:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solymosi/a57c5411a4fdb888b683 to your computer and use it in GitHub Desktop.
Save solymosi/a57c5411a4fdb888b683 to your computer and use it in GitHub Desktop.
Advanced lazy load + Wordpress SEO output buffering fix
<? // just for syntax highlighting
add_action( 'template_redirect', 'lz_ob_start' );
add_action( 'wp_footer', 'lz_rewrite' );
function lz_rewrite()
{
$buffer = ob_get_contents();
ob_end_clean();
$pattern = '/((?:\<img).*)(src)/';
$plugin_dir_path = plugin_dir_url(__FILE__);
$buffer = preg_replace($pattern, "$1 src='" . $plugin_dir_path . "shade.gif' ImageHolder", $buffer);
echo $buffer;
return true;
}
function lz_ob_start()
{
ob_start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment