Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action(
- 'wp_loaded',
- function () {
- remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
- remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageBackgroundLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
- remove_filter( 'jnews_single_image_lazy_owl', array( JNews\Image\ImageNormalLoad::getInstance(), 'owl_lazy_single_image' ), null, 2 );
- $mechanism = get_theme_mod( 'jnews_image_load', 'lazyload' );
- if ( $mechanism === 'lazyload' ) {
- add_filter( 'jnews_single_image_lazy_owl', 'lazy_original_image', null, 2 );
- } elseif ( $mechanism === 'background' ) {
- add_filter( 'jnews_single_image_lazy_owl', 'normal_original_image', null, 2 );
- } else {
- add_filter( 'jnews_single_image_lazy_owl', 'background_original_image', null, 2 );
- }
- },
- 99
- );
- function lazy_original_image( $id, $size ) {
- $image_size = JNews\Image\Image::getInstance()->get_image_size( $size );
- $size = 'full';
- add_filter( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_attr' ), 10, 2 );
- $thumbnail = "<div class=\"thumbnail-container size-{$image_size['dimension']} \">";
- $thumbnail .= wp_get_attachment_image( $id, $size );
- $thumbnail .= '</div>';
- jnews_remove_filters( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageLazyLoad::getInstance(), 'owl_lazy_attr' ), 10 );
- return $thumbnail;
- }
- function normal_original_image( $id, $size ) {
- add_filter( 'wp_lazy_loading_enabled', '__return_false' );
- add_filter( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageNormalLoad::getInstance(), 'normal_load_image' ), 10, 2 );
- $image_size = JNews\Image\Image::getInstance()->get_image_size( $size );
- $size = 'full';
- $thumbnail = "<div class=\"thumbnail-container size-{$image_size['dimension']} \">";
- $thumbnail .= wp_get_attachment_image( $id, $size );
- $thumbnail .= '</div>';
- jnews_remove_filters( 'wp_get_attachment_image_attributes', array( JNews\Image\ImageNormalLoad::getInstance(), 'normal_load_image' ), 10 );
- jnews_remove_filters( 'wp_lazy_loading_enabled', '__return_false' );
- return $thumbnail;
- }
- function background_original_image( $id, $size ) {
- $image = get_post( $id );
- $image_size = wp_get_attachment_metadata( $id );
- $image_dimension = JNews\Image\Image::getInstance()->get_image_size( $size );
- $size = 'full';
- $image_url = JNews\Image\ImageBackgroundLoad::getInstance()->get_image_url( $id, $size );
- if ( ! is_array( $image_size ) ) {
- $image_size = array(
- 'width' => '',
- 'height' => '',
- );
- }
- $alt = JNews\Image\ImageBackgroundLoad::getInstance()->alt_text( $id );
- $expand_range = 700;
- $thumbnail = "<div class=\"thumbnail-container animate-lazy thumbnail-background size-{$image_dimension['dimension']}\">
- <div class=\"lazyload\" {$alt} data-bgset=\"{$image_url}\" data-expand='{$expand_range}' data-full-width=\"{$image_size['width']}\" data-full-height=\"{$image_size['height']}\" alt=\"{$image->post_excerpt}\"></div>
- </div>";
- return $thumbnail;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement