Last active
August 29, 2015 14:01
-
-
Save scofennell/e3da57d85bb951c15b25 to your computer and use it in GitHub Desktop.
WordPress function to change post date to Exif date.
This file contains hidden or 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 | |
/** | |
* Hooks onto an attachment post just after it's created and alters the post date to reflect the EXIF time. | |
* | |
* @param int $attachment_ID The ID of the post we're altering. | |
* @return int The ID of the post we're altering. | |
*/ | |
function sjf_deh_exif_add( $attachment_ID ) { | |
// Grab the exif date for this image | |
$time = sjf_deh_get_exif_date( $attachment_ID ); | |
// If we can't grab the exif date, bail. | |
if( !$time || empty( $time ) ) { return $attachment_ID; } | |
// Build up an array of post attributes for updating the post. | |
$update = array( | |
'ID' => $attachment_ID, | |
'post_date' => $time, | |
); | |
// Update the post. | |
wp_update_post( $update ); | |
return $attachment_ID; | |
} | |
add_filter( 'add_attachment', 'sjf_deh_exif_add' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment