Imagify Optimization & Filter Hooks

This reference guide covers the filter hooks available in Imagify to customize media optimization behavior. You can add these code snippets to a custom plugin or your active child theme’s functions.php file.

Prefer a plugin solution? You can use the Imagify Skipper helper plugin to configure exclusions directly from a simple settings page without touching code. Simply install the plugin and select which file formats (e.g., PDF, GIF) or paths to skip.

1. imagify_get_mime_types

Modifies the array of MIME types supported by Imagify. Unsetting a MIME type here completely removes support for that format plugin-wide across all Imagify workflows (including Media Library eligibility displays, statistics, and optimization runs).

Important Notes:

Parameters

Code Example

/**
 * Prevent Imagify from supporting GIF files site-wide.
 */
add_filter( 'imagify_get_mime_types', function( $mimes ) {
	// Remove specific format: 'gif', 'pdf', 'png', 'jpg'
	unset( $mimes['gif'] );

	return $mimes;
} );

2. imagify_auto_optimize_attachment

Triggers during new media uploads in WordPress. Controls whether Imagify automatically optimizes the attachment upon upload.

Parameters

Code Example

/**
 * Skip automatic optimization on upload for specific MIME types.
 */
add_filter( 'imagify_auto_optimize_attachment', function( $optimize, $attachment_id, $metadata ) {
	// Replace 'image/gif' with target MIME type (e.g., 'image/png', 'application/pdf')
	if ( 'image/gif' === get_post_mime_type( $attachment_id ) ) {
		return false;
	}

	return $optimize;
}, 10, 3 );

3. imagify_bulk_optimize_media

Triggers during Bulk Optimization runs. Allows excluding specific media items, paths, or formats from the bulk optimization queue without affecting auto-upload behavior.

Important Notes:

Parameters

Code Examples

A. Exclude Specific MIME Types from Bulk Run

/**
 * Exclude PDFs from bulk optimization runs.
 */
add_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {
	// Replace 'application/pdf' with target MIME type
	if ( 'wp' === $context && 'application/pdf' === get_post_mime_type( $media_id ) ) {
		return false;
	}

	return $optimize;
}, 10, 3 );

B. Exclude Media Uploaded Before a Specific Date

/**
 * Exclude media items uploaded before a specific date during bulk runs.
 */
add_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {
	if ( 'wp' === $context ) {
		$cutoff_date = '2025-01-01';
		$upload_date = get_the_date( 'Y-m-d', $media_id );

		if ( $upload_date && $upload_date < $cutoff_date ) {
			return false;
		}
	}

	return $optimize;
}, 10, 3 );

C. Exclude Media by Specific Folder or File Path

/**
 * Exclude media items stored in a specific folder path during bulk runs.
 */
add_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {
	if ( 'wp' === $context ) {
		$file_path = get_attached_file( $media_id );

		// Skip media located inside a specific subfolder (e.g., /uploads/2019/ or /uploads/elementor/)
		if ( $file_path && false !== strpos( $file_path, '/uploads/2019/' ) ) {
			return false;
		}
	}

	return $optimize;
}, 10, 3 );