WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

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);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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