3

I want to remove the title attribute from within the output of a [gallery] shortcode e.g.

<a href="url" title="bobby">
   <img src="url" title="bobby"/>
</a>

should be:

<a href="url" >
   <img src="url" />
</a>

I've a feeling this has something to do with the wp_get_attachment_link function.

3
  • Half fixed : remove <img> title attribute
    – bigandy
    Sep 11, 2012 at 16:09
  • Try Trim Or Rtrim In Php Sep 12, 2012 at 4:49
  • Dont mess with all this. Just go to the wordpress dashboard > Media, delete the titles from each picture. Done.
    – user94515
    May 22, 2016 at 21:18

1 Answer 1

1

I've found a solution :

// Remove &lt;img&gt; title attribute in [gallery]
// http://wordpress.org/support/topic/wp_get_attachment_image_attributes-filter-not-working
function remove_img_title($atts) {
    unset($atts['title']);
    return $atts;
}
add_filter('wp_get_attachment_image_attributes','remove_img_title', 10, 4);

// remove title attribute from &lt;a&gt; title attribute in [gallery]
// modified from this post : http://oikos.org.uk/2011/09/tech-notes-using-resized-images-in-wordpress-galleries-and-lightboxes/
function ah_get_attachment_link_filter( $content ) {       

        $new_content = preg_replace('/title=\'(.*?)\'/', '', $content );
        return $new_content;
}
add_filter('wp_get_attachment_link', 'ah_get_attachment_link_filter', 10, 4);

Your Answer

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

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