• I have often uploaded images that have a caption/description but no title in their metadata. It annoys me to no end to have to cut & paste the description into the title field since WP automatically drops the image filename in there if there was no title present.

    This little code snippet can be dropped in your theme’s functions.php file and solve that problem. If an image has a caption/description in its IPTC metadata but no title, the WP title will default to that caption/description.

    Hope this helps someone else out! *if anyone has any suggestions to modifying this filter hook, feel free to throw them out there.

    //If a caption/description was provided in the image IPTC metadata
    //but no title exists, this copies the description to the title field
    //(instead of WP assigning the filename by default)
    function set_default_imgtitle($meta,$file,$sourceImageType) {
    	if($meta['caption'] && (!$meta['title'] || $meta['title'] == ''))
    		$meta['title'] = $meta['caption'];
        	return $meta;
    };
    add_filter('wp_read_image_metadata','set_default_imgtitle',10,3);
  • The topic ‘How to change uploaded image's title default to caption (not filename)’ is closed to new replies.