{"id":19005844,"date":"2026-08-28T18:05:47","date_gmt":"2026-08-28T18:05:47","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/excluding-image-src-translation-globally-with-specific-exceptions\/"},"modified":"2026-08-28T18:05:47","modified_gmt":"2026-08-28T18:05:47","slug":"excluding-image-src-translation-globally-with-specific-exceptions","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/excluding-image-src-translation-globally-with-specific-exceptions\/","title":{"rendered":"Excluding image src translation globally with specific exceptions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi TranslatePress Support,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m looking for some guidance on the recommended way to handle image <code>src<\/code> attribute translation on a large site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Our site currently has approximately <strong>60,000 images across 3,000 URLs<\/strong>, but we only need to translate the <code>src<\/code> attribute for <strong>fewer than 20 specific images<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ideally, I would like the following behaviour:<\/p>\n\n\n\n<ul>\n<li>By default, the <code>src<\/code> attribute of all <code>&lt;img&gt;<\/code> elements should <strong>not be translated<\/strong>.<\/li>\n\n\n\n<li>For the small number of images that do require translation, I would explicitly mark them with a class such as <code>allow-trp<\/code>.<\/li>\n\n\n\n<li>Other attributes on the image, particularly <code>alt<\/code>, should <strong>remain translatable<\/strong>.<\/li>\n\n\n\n<li>I would like to avoid using a selector such as <code>img:not(.allow-trp)<\/code>, as your documentation recommends avoiding <code>:not()<\/code> selectors.<\/li>\n\n\n\n<li>I also don&#8217;t want to exclude the entire <code>&lt;img&gt;<\/code> element using <code>img<\/code> or <code>data-no-translation<\/code>, because that would prevent other attributes such as <code>alt<\/code> from being translated.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the desired behaviour would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- src should NOT be translated, alt SHOULD be translated --&gt;\n&lt;img src=\"\/images\/example.jpg\" alt=\"Some translatable text\"&gt;\n\n&lt;!-- src SHOULD be translated, alt SHOULD also be translated --&gt;\n&lt;img class=\"allow-trp\" src=\"\/images\/example.jpg\" alt=\"Some translatable text\"&gt;\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Is there a <strong>supported TranslatePress filter, hook, or configuration option that allows translation to be disabled specifically for the <code>src<\/code> attribute of <code>&lt;img&gt;<\/code> elements by default, while allowing individual images to opt back in via a class or other attribute?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I&#8217;m particularly interested in an approach that doesn&#8217;t require TranslatePress to process or evaluate all 60,000 images unnecessarily, given that fewer than 20 actually require <code>src<\/code> translation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there is a recommended implementation for this scenario, including a PHP filter or example code, I&#8217;d appreciate it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks,<br \/>Qiniso<\/p>\n","protected":false},"template":"","class_list":["post-19005844","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19005844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/19005844\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=19005844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}