Created
November 6, 2012 14:43
-
-
Save michael-cannon/4025107 to your computer and use it in GitHub Desktop.
Correctly import image caption as caption than description in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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