• Is it possible to add some code (functions.php?) to get existing images to display – on mouse-over – the title attributes of images?

    I understand that there is at least one plugin that will do this for new images uploaded but not wishing to add yet another plugin, or to re-upload several thousand images, surely some coding should be possible?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If you intend for the title attribute to be added to the img tag when images are inserted into post content using the media library, you can use the ‘image_send_to_editor’ filter to alter the sent HTML in any way you like. Your filter callback is passed a slew of image meta data that can be used to make such alterations.

    Once again though, this will not affect img tags already in content, though it will at least affect newly inserted old images. To alter existing content, you are better off running a one time script that seeks out img tags with no title attribute and updates the content to include them.

    Note that title attributes have some accessibility issues. Depending on why you want them, there might be a better way. See https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title#Accessibility_concerns

Viewing 1 replies (of 1 total)
  • The topic ‘How to add title attribute to existing images?’ is closed to new replies.