Skip to content

Instantly share code, notes, and snippets.

@markonikolic985
Created February 24, 2021 06:36
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 markonikolic985/36d58e114474c54e56228e8bd02fbd96 to your computer and use it in GitHub Desktop.
Save markonikolic985/36d58e114474c54e56228e8bd02fbd96 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Imagify: Skip &lt;picture&gt; Tag Replacement
* Description: Skip &lt;picture&gt; tag replacement for &lt;img&gt; tags that are already in &lt;picture&gt; tags. Just add either data-itoi-skip-picture="yes" attribute or "itoi-skip-picture" class to &lt;img&gt; tags that should be skipped.
* Version: 1.0
* Author: WP Media
* Author URI: https://wp-media.me/
* Licence: GPLv2
*
* Copyright 2021 WP Media
*/
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
add_filter( 'imagify_webp_picture_images_to_display', 'itoi_skip_picture_tag_replacement' );
function itoi_skip_picture_tag_replacement( $images ) {
foreach ( $images as $i => $image ) {
if ( $image[ 'attributes' ][ 'data-itoi-skip-picture' ] === 'yes'
|| preg_match( '/\bitoi-skip-picture\b/', $image[ 'attributes' ][ 'class' ] )
) {
unset( $images[ $i ] );
}
}
return $images;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment