0

I have been looking for a couple of days for a filter for the WordPress gallery. I have tried many different codes but nothing seems to work for it. I am not using a plugin. I am talking about the stock gallery

I created a 2 column WordPress gallery and inserted it into a page. This did make a 2 column gallery but it also made the image sizes to 128 x 49. The site is responsive and the image sizes should be around 400 by 200. So I thought that if I could get WordPress to take out the inline height and width that the responsive part would take over and fill the available space. The filters that I have tried have worked on other images just not the gallery. I am using the 2014 theme and it's media queries. Is there a specific filter for the gallery?

Here is the filter I am using for other images

 add_filter('wp_get_attachment_link', 'remove_img_width_height', 10, 1);

function remove_img_width_height($html) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}
  • 1
    Possible duplicate of 4343 – helgatheviking Mar 26 '14 at 21:47
  • It's not a duplicate. That post is talking about a plugin using shortcodes and limiting the amount of images posted. I tried the filter in that post and it didn't work. – Jamie Mar 26 '14 at 22:44
  • 1
    You asked for a way to filter the WordPress gallery. post_gallery is that filter. You might need to adapt the specific filter to your purposes, but that's the right place to start. – helgatheviking Mar 26 '14 at 22:59
  • @helgatheviking You should just mark it in a close vote, so we can inspect it. Thanks :) – kaiser Mar 27 '14 at 0:03
  • Removing the inline tags will probably not help. CSS cam override those. – s_ha_dum Mar 27 '14 at 0:13
0

As an alternative to removing the image sizes (which digging a little deeper looks very complicated), why not change the size of the images in your gallery? If you use a larger image they will "fill the space" at larger screens and then shrink down for smaller screens.

The Gallery shortcode has a size parameter (with thumbnail as the default)... that is weirdly not available in the media library, but can be entered in the HTML editor.

[gallery link="none" ids="94,92,85" size="medium"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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