Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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