• This sounds just what I need — the “title” attribute is missing from all my WordPress Gallery thumbnails on my Pages….despite all fields being filled on each image.

    So I install your Plugin and Activated it…but am still missing the “title” attribute….

    What am I doing wrong? By the way, my theme is a child of TwentyTwelve. I have only copied header.php and footer.php to my child.

    Do I need to do something else?

    Thanks for you time!

    https://www.ads-software.com/plugins/restore-image-title/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Les Bessant

    (@lesbessant)

    It does work for galleries in posts and pages, and there’s no reason it shouldn’t work with your theme (I’m also using a TwentyTwelve child theme with minimal changes).

    But, and I’m afraid it’s a big but, the plugin is a very simple thing – it fires when an image is inserted into a post, and adds the title attribute to the inserted code (after checking that there isn’t a title there already).

    It won’t do anything to existing posts – as far as I can remember, I had to edit a load of old posts (remove image, add it back) to get the titles to show under thumbnails.

    If you’ve got a lot of galleries, this might be a lot of work. There might be a better solution, but it would take a better coder than me to come up with it.

    Sorry I can’t be of more help.

    Thread Starter electricwatches

    (@electricwatches)

    Thanks for you reply.

    I did a bit more sleuthing around and decided the best place to add the title attribute was to edit the wp_get_attachment_image function in wp_includes/media.php file.

    I’m too new to WP to understand whether it was possible to override this function in my local functions.php, so edited media.php directly but it does the trick and works well. Added the “title” related lines in the code below:

    $default_attr = array(
    			'src'	=> $src,
    			'class'	=> "attachment-$size",
    			'alt'	=> trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
    			'title'	=>trim(strip_tags( $attachment->post_title )),
    		);
    		if ( empty($default_attr['alt']) )
    			$default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
    		if ( empty($default_attr['alt']) )
    			$default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
    
    		if ( empty($default_attr['title']) )
    			$default_attr['title'] = trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )); // Use Alt for Title if Title not set
    OC2PS

    (@sooskriszta)

    Seems to be a better solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Does it work with Pages?’ is closed to new replies.