Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lazy-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ static function setup_filters() {
add_filter( 'the_content', array( __CLASS__, 'add_image_placeholders' ), 99 ); // run this later, so other content filters have run, including image_add_wh on WP.com
add_filter( 'post_thumbnail_html', array( __CLASS__, 'add_image_placeholders' ), 11 );
add_filter( 'get_avatar', array( __CLASS__, 'add_image_placeholders' ), 11 );

if ( apply_filters( 'lazy_load_kses_allowed_html', false ) ) {
add_filter( 'wp_kses_allowed_html', array( __CLASS__, 'allowed_post_tags' ), 10, 2 );
}
}

static function add_scripts() {
Expand Down Expand Up @@ -102,6 +106,14 @@ static function is_enabled() {
static function get_url( $path = '' ) {
return plugins_url( ltrim( $path, '/' ), __FILE__ );
}

public function allowed_post_tags( $allowedposttags, $context ) {
if ( 'post' === $context && ! empty( $allowedposttags['img'] ) ) {
$allowedposttags['img']['data-lazy-src'] = true;
$allowedposttags['noscript'] = array();
}
return $allowedposttags;
}
}

function lazyload_images_add_placeholders( $content ) {
Expand Down