My Title Has Been Restored

Update: some helpful advice from OllieJones on the WordPress forum helped me improve the plugin – it now checks that there isn’t already a title, and if there is it won’t add it again. It also deals with any HTML tags that might be in the title. The original version didn’t do that, which could have led to some very mangled image tags. The revised version is now available from the WordPress Plugin Directory.

It seems like only a couple of days ago[1] that I was muttering about how WordPress 3.5 had stopped inserting the title attribute of images inserted into posts. While this was only a minor inconvenience, it irritated me enough to (a) moan about it and (b) try to change it.

I’d done a fair amount of reading, which led me to believe that a simple function (and it would have to be simple, given my coding skill level) should be able to do what I needed. One of the great things about WordPress is that it’s designed to be fiddled with. It offers numerous “hooks” and “filters”, which, put in the basic terms that a non-programmer like me can understand, allow you to change almost everything it does. Want to insert some extra text? Want to stop something displaying? Chances are that there’s a hook or filter you can use.

In this particular case, it seemed that what I needed to play with was the


filter. And after much googling, and much trial, and and even more error, I came up with a function that does exactly what I needed. As I didn’t want to break things, rather than adding it to my general purpose Functionality plugin, I created it as a shiny new plugin all to itself. And sure enough, with this plugin activated, when I insert an image, the title attribute is inserted. This ensures that the tooltip appears, and lightbox plugins no longer get confused.

It’s such a short and simple thing[2], that I can include the whole of it here:

Download the plugin from the WordPress Plugin Directory

This has only been tested on my own sites, where it didn’t appear to break anything. Use at your own risk. If you happen to be a real programmer, you may point and laugh as much as seems appropriate. Or if you’re a real programmer and you have advice or suggestions to improve what I’ve done, I’d be happy to receive them.

[1] Probably because it was
[2] It would have to be, for reasons previously mentioned

2 thoughts on “My Title Has Been Restored

  1. Pingback: They took my title away! | Losing it

  2. Pingback: Restore Image Title – A WordPress Plugin | Losing it

Comments are closed.