Remove title attribute from WordPress images

I use default WordPress functions to insert images very often. Functions like the_post_thumbnail or wp_get_attachment_image are used in almost every project I do.

By default WordPress adds a title to all of the images printed by these functions, and the title usually is nothing more than the filename.

The result is a lot of title attributes which are pretty much useless and just distracting (while hovering an image for instance).

But thankfully WordPress filters saves us as they often do.

Filter wp_get_attachment_image_attributes and unset the title attribute.

function mytheme_wp_get_attachment_image_attributes( $attr ) {

unset($attr['title']);

 return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'mytheme_wp_get_attachment_image_attributes' );

After that you should be set!

Advertisements
About

Web Developer @ Oakwood Creative - www.oakwood.se

Tagged with: , , , , ,
Posted in Intermediate
4 comments on “Remove title attribute from WordPress images
  1. Thankfully stumbled on your post and just wanted to take the time to say thank you 🙂
    Saved me quite some time of frustrated hair-pulling there!

  2. rmccastro says:

    Hello Dear Vincent,

    How can i do this, using CSS? I have a wordpress.com account and therefore my only chance of changing this is via CSS editor

    Thanks

    Regards

  3. James says:

    HI
    Where do I put this code in order to make it work, I need to hide all titles on images in a site

  4. James says:

    I have tried adding in footer.php and header but the text just shows in the page and the title is still there,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

About

WordPress Quick Tips is a blog supplying great tips about WordPress.

We hope to create a great knowledge resource for WordPress developers as well as serving a reminder for all the forgetful ones.

The blog is created and run by Vincent of Oakwood Creative

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 120 other followers

%d bloggers like this: