How do I filter title and alt attributes in the gallery shortcode?

The shortcode is parsed by gallery_shortcode(), which calls wp_get_attachment_link(), which in turns calls wp_get_attachment_image(). This latter function writes the <img> tag with the title attribute. You’re lucky, because the attributes are filtered through wp_get_attachment_image_attributes, so you can hook into that and remove the title.

To do this, you attach the hook before you call the shortcode and remove it after you did this. You can either do this in your template if it’s a one-off, or, if you are more advanced, you “hijack” the shortcode with your own function that adds the hook, calls the original gallery_shortcode() function, and removes the hook.

tech