{"id":1316,"date":"2026-07-30T06:30:39","date_gmt":"2026-07-30T06:30:39","guid":{"rendered":"https:\/\/imagify.io\/documentation\/?p=1316"},"modified":"2026-07-31T13:57:47","modified_gmt":"2026-07-31T13:57:47","slug":"imagify-optimization-filter-hooks","status":"publish","type":"post","link":"https:\/\/imagify.io\/documentation\/imagify-optimization-filter-hooks\/","title":{"rendered":"Imagify Optimization &amp; Filter Hooks"},"content":{"rendered":"<p>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&#8217;s <code>functions.php<\/code> file.<\/p>\n<h2>1. imagify_get_mime_types<\/h2>\n<p>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).<\/p>\n<p><strong>Important Notes:<\/strong><\/p>\n<ul>\n<li>Unsetting a MIME type will not un-optimize or restore files of that type that were already optimized in the past.<\/li>\n<li>This filter runs on different media contexts (images, PDFs, or both). Always use <code>unset()<\/code> to remove a specific format instead of returning a new fixed array.<\/li>\n<\/ul>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li><code>array $mimes<\/code> \u2014 Array of supported extensions and MIME types.<\/li>\n<\/ul>\n<p><strong>Code Example<\/strong><\/p>\n<div class=\"wp-block-code\">\n<pre class=\"wp-block-code\"><code>\/**\n * Prevent Imagify from supporting GIF files site-wide.\n *\/\nadd_filter( 'imagify_get_mime_types', function( $mimes ) {\n\t\/\/ Remove specific format: 'gif', 'pdf', 'png', 'jpg'\n\tunset( $mimes['gif'] );\n\n\treturn $mimes;\n} );<\/code><\/pre>\n<\/div>\n<h2>2. imagify_auto_optimize_attachment<\/h2>\n<p>Triggers during new media uploads in WordPress. Controls whether Imagify automatically optimizes the attachment upon upload.<\/p>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li><code>bool $optimize<\/code> \u2014 Whether to optimize the attachment. Default: <code>true<\/code>.<\/li>\n<li><code>int $attachment_id<\/code> \u2014 The WordPress attachment ID.<\/li>\n<li><code>array $metadata<\/code> \u2014 Attachment metadata array.<\/li>\n<\/ul>\n<p><strong>Code Example<\/strong><\/p>\n<div class=\"wp-block-code\">\n<pre class=\"wp-block-code\"><code>\/**\n * Skip automatic optimization on upload for specific MIME types.\n *\/\nadd_filter( 'imagify_auto_optimize_attachment', function( $optimize, $attachment_id, $metadata ) {\n\t\/\/ Replace 'image\/gif' with target MIME type (e.g., 'image\/png', 'application\/pdf')\n\tif ( 'image\/gif' === get_post_mime_type( $attachment_id ) ) {\n\t\treturn false;\n\t}\n\n\treturn $optimize;\n}, 10, 3 );<\/code><\/pre>\n<\/div>\n<h2>3. imagify_bulk_optimize_media<\/h2>\n<p>Triggers during Bulk Optimization runs. Allows excluding specific media items, paths, or formats from the bulk optimization queue without affecting auto-upload behavior.<\/p>\n<p><strong>Important Notes:<\/strong><\/p>\n<ul>\n<li>This filter only applies to the bulk <strong>Optimization<\/strong> process. It does not affect Bulk <em>Restore<\/em> or <em>&#8220;Generate Missing Next-Gen Images&#8221;<\/em> runs.<\/li>\n<li>The total <em>&#8220;X media to optimize&#8221;<\/em> count displayed on the Bulk Optimization page is calculated separately, so excluded items will still be included in the displayed total count.<\/li>\n<\/ul>\n<p><strong>Parameters<\/strong><\/p>\n<ul>\n<li><code>bool $optimize<\/code> \u2014 Whether to optimize this item. Default: <code>true<\/code>.<\/li>\n<li><code>int $media_id<\/code> \u2014 The media item ID (attachment ID or custom folder file ID).<\/li>\n<li><code>string $context<\/code> \u2014 Optimization context (<code>'wp'<\/code> or <code>'custom-folders'<\/code>).<\/li>\n<li><code>int $optimization_level<\/code> \u2014 Selected optimization level (<code>0<\/code> = Normal, <code>1<\/code> = Aggressive, <code>2<\/code> = Ultra).<\/li>\n<\/ul>\n<p><strong>Code Examples<\/strong><\/p>\n<h4>A. Exclude Specific MIME Types from Bulk Run<\/h4>\n<div class=\"wp-block-code\">\n<pre class=\"wp-block-code\"><code>\/**\n * Exclude PDFs from bulk optimization runs.\n *\/\nadd_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {\n\t\/\/ Replace 'application\/pdf' with target MIME type\n\tif ( 'wp' === $context &amp;&amp; 'application\/pdf' === get_post_mime_type( $media_id ) ) {\n\t\treturn false;\n\t}\n\n\treturn $optimize;\n}, 10, 3 );<\/code><\/pre>\n<\/div>\n<h4>B. Exclude Media Uploaded Before a Specific Date<\/h4>\n<div class=\"wp-block-code\">\n<pre class=\"wp-block-code\"><code>\/**\n * Exclude media items uploaded before a specific date during bulk runs.\n *\/\nadd_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {\n\tif ( 'wp' === $context ) {\n\t\t$cutoff_date = '2025-01-01';\n\t\t$upload_date = get_the_date( 'Y-m-d', $media_id );\n\n\t\tif ( $upload_date &amp;&amp; $upload_date &lt; $cutoff_date ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn $optimize;\n}, 10, 3 );<\/code><\/pre>\n<\/div>\n<h4>C. Exclude Media by Specific Folder or File Path<\/h4>\n<div class=\"wp-block-code\">\n<pre class=\"wp-block-code\"><code>\/**\n * Exclude media items stored in a specific folder path during bulk runs.\n *\/\nadd_filter( 'imagify_bulk_optimize_media', function( $optimize, $media_id, $context ) {\n\tif ( 'wp' === $context ) {\n\t\t$file_path = get_attached_file( $media_id );\n\n\t\t\/\/ Skip media located inside a specific subfolder (e.g., \/uploads\/2019\/ or \/uploads\/elementor\/)\n\t\tif ( $file_path &amp;&amp; false !== strpos( $file_path, '\/uploads\/2019\/' ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn $optimize;\n}, 10, 3 );<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s functions.php file. 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1316","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/1316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/comments?post=1316"}],"version-history":[{"count":4,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/1316\/revisions"}],"predecessor-version":[{"id":1321,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/posts\/1316\/revisions\/1321"}],"wp:attachment":[{"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/media?parent=1316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/categories?post=1316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imagify.io\/documentation\/wp-json\/wp\/v2\/tags?post=1316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}