I am filtering post_thumbnail_html in my theme to modify the output of my image tags. I have one template part that I would like this filter not to apply to. It uses an image-size that is used no were else in the theme. So I am looking for a way to have this filter not apply on a specific template part or for a specific image size, either way works. Is this possible.

I don't think the filter itself matters, but just in case here it is:

 if (! function_exists('_sf_responsive_img') ) :
 function _sf_responsive_img($html, $post_id, $post_thumbnail_id, $size, $attr) {
     //make image links
     $attachment_id = $post_thumbnail_id;
     $default = wp_get_attachment_image_src($attachment_id);
     $size = 'fd-sm';
     $small = wp_get_attachment_image_src($attachment_id, $size);
     $size = 'fd-med';
     $med = wp_get_attachment_image_src($attachment_id, $size);
     $size = 'fd-lrg';
     $lrg = wp_get_attachment_image_src($attachment_id, $size);
     //create image tag with queries
     $html = '<img src="'.$default[0].'"';
     $html .= 'data-interchange="['.$default[0].', (default)],';
     $html .= '['.$small[0].', (only screen and (min-width: 320px))],';
     $html .= '['.$med[0].', (only screen and (min-width: 768px))],';
     $html .= '['.$lrg[0].', (only screen and (min-width: 1024px))],';
     $html .='">';
     return $html;
 add_filter('post_thumbnail_html', '_sf_responsive_img', 5, 5);
 endif; // ! _sf_responsive_img exists

1 Answer 1


Probably the simplest solution is to remove the filter before output:

// remove the filter
remove_filter('post_thumbnail_html', '_sf_responsive_img', 5, 5);
// output template
get_template_part( 'something' );
// add the filter back on if other code below outputs thumbs that need the filter
add_filter('post_thumbnail_html', '_sf_responsive_img', 5, 5);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.