Skip to content

Instantly share code, notes, and snippets.

@michael-cannon
Created November 6, 2012 14:43
Show Gist options
  • Save michael-cannon/4025107 to your computer and use it in GitHub Desktop.
Save michael-cannon/4025107 to your computer and use it in GitHub Desktop.
Correctly import image caption as caption than description in WordPress
<?php
function add_attachment_caption( $meta, $attachment_id ) {
if ( ! empty( $meta['image_meta']['caption'] ) ) {
$data = array(
'ID' => $attachment_id,
// remove wrongly imported caption as description field
'post_content' => '',
'post_excerpt' => $meta['image_meta']['caption'],
);
wp_update_post( $data );
}
return $meta;
}
add_filter('wp_generate_attachment_metadata', 'add_attachment_caption', '', 2);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment