{"id":947,"date":"2024-05-07T11:46:07","date_gmt":"2024-05-07T11:46:07","guid":{"rendered":"https:\/\/kb.shortpixel.com\/docs\/exclude-old-images-from-optimization-and-automatically-optimize-the-new-images\/"},"modified":"2025-08-27T08:39:48","modified_gmt":"2025-08-27T08:39:48","password":"","slug":"exclude-old-images-from-optimization-and-automatically-optimize-the-new-images","status":"publish","type":"docs","link":"https:\/\/kb.shortpixel.com\/knowledge-base\/article\/exclude-old-images-from-optimization-and-automatically-optimize-the-new-images\/","title":{"rendered":"Exclude old images from optimization and automatically optimize the new images"},"content":{"rendered":"\n<p>Imagine a scenario where your website has already uploaded <strong>and optimized<\/strong>\u00a0many images.\u00a0Now you decide to use ShortPixel Image Optimizer to compress <strong>only<\/strong> your new images that you upload from now on. No problem, you say, you can just enable the <a href=\"https:\/\/shortpixel.com\/knowledge-base\/article\/settings-optimize-media-on-upload\/\" rel=\"noopener\">Optimize media on upload<\/a> option and that&#8217;s it. But there&#8217;s a catch: once you run the bulk optimization on Media > Bulk ShortPixel, the plugin will optimize all your images, <strong>even the old ones<\/strong>.\u00a0This can be problematic, as you might end up with over-optimized images and you&#8217;ll probably spend too many unnecessary credits.<\/p>\n\n\n\n<p>The solution lies in the <a href=\"https:\/\/shortpixel.com\/knowledge-base\/article\/88-how-to-exclude-images-from-being-optimized\" rel=\"noopener\">Exclude patterns<\/a> setting.<\/p>\n\n\n\n<section class=\"callout-yellow\"><strong>Attention!<\/strong> This solution only works if you have always had enabled the setting &#8220;Organize my uploads into month- and year-based folders&#8221; in the WordPress Media settings. This way, the URLs of your images will look like this: https:\/\/mydomain.com\/wp-content\/uploads\/2018\/08\/image.jpg<\/section>\n\n\n\n<h2 class=\"wp-block-heading\">Exclusion by year<\/h2>\n\n\n\n<p>Suppose you want to exclude all images uploaded <strong>before 2022<\/strong> from optimization. Go to the Exclude patterns field, choose an &#8220;Image Path&#8221; exclusion type, select &#8220;Check as regular expression&#8221; and write the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\\\/(19[0-9][0-9]|20[01][0-9]|202[01])\\\/\/<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation<\/h3>\n\n\n\n<p>You need to understand how these regular expressions work if you want to further customize your filter. Therefore, let us explain each part of the previous example.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first and the last <code>\/<\/code> are always required.<\/li>\n\n\n\n<li>Each of the <code>\\\/<\/code> matches the slash before and after the year in the URL: <code>...uploads<strong>\/<\/strong>2018<strong>\/<\/strong>08...<\/code><\/li>\n\n\n\n<li>The parenthesis are used as a capture group for the next part, which is <code>19[0-9][0-9]|20[01][0-9]|202[01]<\/code>.\n<ul class=\"wp-block-list\">\n<li>The expression has three parts separated by <code>|<\/code>. The first is <code>19[0-9][0-9]<\/code>, which means that it matches any 4-digit number that starts with 19.<\/li>\n\n\n\n<li>The second is <code>20[01][0-9]<\/code>, which means it matches any number from 2000 to 2019: 20 always stays the same, the third digit can be 0 or 1, and the fourth can be anything.<\/li>\n\n\n\n<li>The third part is <code>202[01]<\/code>. This matches 2020 or 2021; the only change is the last digit.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Other examples<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Exclude images uploaded before 2018: <code>\/\\\/(19[0-9][0-9]|200[0-9]|201[0-7])\\\/\/<\/code><\/li>\n\n\n\n<li>Exclude images uploaded before 2007: <code>\/\\\/(19[0-9][0-9]|200[0-6])\/\\\/<\/code><\/li>\n\n\n\n<li>Exclude images uploaded before 1999: <code>\/\\\/(19[0-8][0-9]|199[0-8])\/\\\/<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Exclusion by year and month<\/h2>\n\n\n\n<p>Suppose you want to exclude from optimization all images uploaded before May 2022. Go to the Exclude patterns field, choose an &#8220;Image Path&#8221; exclusion type, select &#8220;Check as regular expression&#8221; and write the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\\\/((19[0-9][0-9]|20[01][0-9]|202[01])|2022\/0[1-4])\\\/\/<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explanation<\/h3>\n\n\n\n<p>Here we use the parenthesis to capture two groups: either all months from all years from 1900 to 2021 (<code>19[0-9][0-9]|20[01][0-9]|202[01]<\/code>) or January to April 2022 (<code>2022\/0[1-4]<\/code>). That&#8217;s effectively excluding anything before May 2022.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other examples<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Exclude images uploaded before November 2015: <code>\/\\\/((19[0-9][0-9]|200[0-9]|201[0-4])|2015\/0[1-9]|2015\/10)\/\\\/<\/code><\/li>\n\n\n\n<li>Exclude images uploaded before March 2008: <code>\/\\\/((19[0-9][0-9]|200[0-7])|2008\/0[12])\/\\\/<\/code><\/li>\n\n\n\n<li>Exclude images uploaded before August 1999: <code>\/\\\/(199[0-8]|1999\/0[1-7])\/\\\/<\/code><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Imagine a scenario where your website has already uploaded and optimized\u00a0many images.\u00a0Now you decide to use ShortPixel Image Optimizer to compress only your new images that you upload from now on. No problem, you say, you can just enable the Optimize media on upload option and that&#8217;s it. But there&#8217;s a catch: once you run [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"doc_category":[37],"glossaries":[],"doc_tag":[],"class_list":["post-947","docs","type-docs","status-publish","hentry","doc_category-shortpixel-image-optimizer"],"blocksy_meta":[],"year_month":"2026-04","word_count":443,"total_views":"2422","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"admin","author_nicename":"admin_mdli53m5","author_url":"https:\/\/kb.shortpixel.com\/author\/admin_mdli53m5\/"},"doc_category_info":[{"term_name":"ShortPixel Image Optimizer","term_url":"https:\/\/kb.shortpixel.com\/knowledge-base\/category\/shortpixel-image-optimizer\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/comments?post=947"}],"version-history":[{"count":2,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/947\/revisions"}],"predecessor-version":[{"id":1377,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/docs\/947\/revisions\/1377"}],"wp:attachment":[{"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/doc_category?post=947"},{"taxonomy":"glossaries","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/glossaries?post=947"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/kb.shortpixel.com\/wp-json\/wp\/v2\/doc_tag?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}