Skip to content

Instantly share code, notes, and snippets.

@ayn
Created June 3, 2010 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayn/a2db759e9f8b1ba7c97b to your computer and use it in GitHub Desktop.
Save ayn/a2db759e9f8b1ba7c97b to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: jQuery lazy load plugin
Plugin URI: http://github.com/ayn/wp-jquery-lazy-load/
Description: a quick and dirty wordpress plugin to enable image lazy loading.
Version: v0.10
Author: Andrew Ng
Author URI: http://blog.andrewng.com
*/
function jquery_lazy_load_headers() {
$plugin_path = plugins_url('/', __FILE__);
$lazy_url = $plugin_path . 'javascripts/jquery.lazyload.mini.js';
$jq_url = 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
wp_deregister_script('jquery');
wp_enqueue_script('jquery', $jq_url, false, '1.4.2');
wp_enqueue_script('jquerylazyload', $lazy_url, 'jquery', '1.5.0');
}
function jquery_lazy_load_ready() {
$placeholdergif = plugins_url('images/grey.gif', __FILE__);
echo <<<EOF
<script type="text/javascript">
jQuery(document).ready(function($){
if (navigator.platform == "iPad") return;
jQuery("div").not(".wpn_featured.wpn_expandableimg").find("img").lazyload({
effect:"fadeIn",
placeholder: "$placeholdergif"
});
});
</script>
EOF;
}
add_action('wp_head', 'jquery_lazy_load_headers', 5);
add_action('wp_head', 'jquery_lazy_load_ready', 12);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment