Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Plugin Name: Wpsmush - Exclude Specific Attachments From Smushing
* Plugin URI: https://premium.wpmudev.org/
* Description: This plugin will help to exclude specific attachments from optimizing
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function exclude_attachment_from_smushing( $smush, $id ) {
// attachment ids to skip smushing
$attachment_ids = array( 1 ); // example: array( 2, 4, 5 );
$matched = in_array( $id, $attachment_ids );
if ( ! $matched ) return $smush;
update_post_meta( $id, 'wp-smpro-smush-data', 'skipped' );
return false;
}
add_filter( 'wp_smush_image', 'exclude_attachment_from_smushing', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.