Title: Exclude image with low width?
Last modified: April 10, 2021

---

# Exclude image with low width?

 *  [Giang Le](https://wordpress.org/support/users/gianghl1983/)
 * (@gianghl1983)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/exclude-image-with-low-width/)
 * Hi,
 * I am trying to exclude some images and using this filter but it doesn’t work (
   exclude image which has width < 500).
 * Please help!
 *     ```
       /**
       	 * This filter allows to programatically prevent watermarking certain
       	 * attachment if <code>false</code> returned from attached function.
       	 *
       	 * @param boolean   $should_apply       Whether the image should be watermarked. Return false to prevent watermarking.
       	 * @param Watermark $watermark          Watermark object.
       	 * @param integer   $attachment_id      Attachment ID.
       	 * @param WP_Post   $attachment         Attachment post.
       	 * @param array     $meta               Attachment metadata.
       	 * @param array     $applied_watermarks Array containing all watermarks applied to this attaachment.
       	 * 	
       	 */
   
       add_filter( 'easy-watermark/should-apply-watermark','dont_watermark', 10, 6 );
       function dont_watermark ($is_watermark, $watermark, $attachment_id, $attachment, $meta, $applied_watermarks)
       	{	
       		//$meta = wp_get_attachment_metadata($attachment_id);
       		//echo 'tada';
       		//$title 		= 'Image Debug';
       		$width 	= $meta['width'];
       		// $message 	= '300px';
       		// //$parent 	= 1; // This might be the ID of a payment post type item we want this log item connected to
       		// //$type 		= 'event';
   
       		// //WP_Logging::add( $title, $message, $parent, $type );
       		// WP_Logging::add( $title, $message );
   
       		if( $meta['width'] < 500 ) {
       			$is_watermark = false;//no WM
       		} else {
       			$is_watermark = true;
       		}
       		return $is_watermark;
   
       	}
       ```
   
    -  This topic was modified 5 years, 2 months ago by [Giang Le](https://wordpress.org/support/users/gianghl1983/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Kuba Mikita](https://wordpress.org/support/users/kubitomakita/)
 * (@kubitomakita)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/exclude-image-with-low-width/#post-14368820)
 * Hi, it looks good, but there’s a couple of things to check:
 * – does it ever execute this filter?
    – what’s in the `$meta` var exactly, can
   you confirm you get the values expected?
 *  Thread Starter [Giang Le](https://wordpress.org/support/users/gianghl1983/)
 * (@gianghl1983)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/exclude-image-with-low-width/#post-14369495)
 * [@kubitomakita](https://wordpress.org/support/users/kubitomakita/) Thanks for
   your reply! No it does not execute the filter (code did not run). I am not so
   sure what $meta is (your code….) but I suppose it has value with $meta = wp_get_attachment_metadata(
   $attachment_id); –> $meta[‘width’]

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exclude image with low width?’ is closed to new replies.

 * ![](https://ps.w.org/easy-watermark/assets/icon.svg?rev=2153955)
 * [Easy Watermark](https://wordpress.org/plugins/easy-watermark/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easy-watermark/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easy-watermark/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-watermark/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-watermark/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-watermark/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Giang Le](https://wordpress.org/support/users/gianghl1983/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/exclude-image-with-low-width/#post-14369495)
 * Status: not resolved