Was trying to upload some photos and noticed that the captions I had set on the photos in Picasa showed up as titles in WordPress instead of as captions. Examining the core code, I found that it’s a known issue, but that fixing it in the core isn’t so easy, since WordPress has to support a number of different image editing programs and such. Different programs use the EXIF fields in different ways.

But I mostly use Picasa for photo management, so I don’t care about those other programs. So I wrote a quick plugin to fix the problem with WordPress and Picasa photos. Basically it just rejiggers the attachment when it’s added (but not when it’s edited) and puts the caption in the right place.

<?php
/**
Plugin Name: Picasa Captioner
Description: Fix up WordPress to read Picasa Captions from EXIF info properly.
Author: Otto
Author URI: http://ottodestruct.com/
**/

add_filter( 'wp_read_image_metadata', 'picasa_adjust_caption' );
function picasa_adjust_caption($meta) {
	if (empty($meta['caption']) && !empty($meta['title'])) {
		$meta['caption'] = $meta['title'];
		$meta['title'] = '';
	}
	return $meta;
}

add_action( 'add_attachment', 'picasa_adjust_attachment' );
function picasa_adjust_attachment($id) {
	$attachment = & get_post( $id, ARRAY_A );
	if ( !empty( $attachment ) ) {
		$attachment['post_excerpt'] = $attachment['post_content'];
		$attachment['post_content'] = '';
		wp_update_post($attachment);
	}
}
Shortlink:

8 Comments

  1. Brilliant, congratulations.
    Thanks for sharing.

  2. Great idea. I would love to see facebook photo implementation. The fact that it has unlimited photo space is the plus.

  3. you’re genius. I am not (particularly in this area). Are you using the Vodpod plugin to get Picassa into WordPress? That’s the solution I’ve found so far. and today discovered the captions issue. I pasted your code into the html portion of the WYSIWYG but no change. Where does this code go? Above or below the Vodpod code?

    Do you also, perchance, have a solution for getting slideshows to appear in the emails that are sent when you post something new?

    Thank you!!

    • I’m not using any plugin, and don’t know what “Vodpod” is. I’m using the normal WordPress media system.

      And this is a normal plugin. You put it in a PHP file, put it in the WordPress plugins directory, and activate the plugin.

      • Thanks for the reply. I admittedly don;t really know what Vodpod is either! it’s a workaround I found through Google to insert a slideshow from Flickr or Picasa and it makes them video somehow…? I use that instead of the WP slideshow bc you can’t have a picture in the post and then different pictures in the slideshow – it pulls the post photo into the slideshow. Perhaps more detail than you needed…! I’ll explore your way, too.

  4. […] a quick bit of code to fix it for my case. You could use something similar for yours.More here: http://ottopress.com/2011/picasa…This answer .Please specify the necessary improvements. Edit Link Text Show answer summary […]

  5. […] I did a bit of searching, and eventually found a post by Otto describing a problem he had run into when inserting images from Picasa. He included the code of a […]

  6. The confusion regarding IPTC field import is due to the International Press Communication Council (IPTC) has called the caption field a description field.
    “A textual description, including captions, of the item’s content, particularly used where the
    object is not text.”

    So when WordPress Core decided import the IPTC meta data they mapped the Description Field to Description field (in WordPress) and thus we have this confusion.

    Most North American media organizations and some IPTC (or meta data) editors call this the caption field even though officially is called the Description field as it describes the photo.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Need to post PHP code? Wrap it in [php] and [/php] tags.