WordPress Quick Tips

Remove title attribute from WordPress images

Posted by: Vincent on: January 5, 2012

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!

Advertisement

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 )

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 69 other followers

Follow

Get every new post delivered to your Inbox.

Join 69 other followers