Skip to content

Instantly share code, notes, and snippets.

@wplokal
Created March 19, 2019 02:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wplokal/2ce8dba2196dc4ac7d0704f582644ed1 to your computer and use it in GitHub Desktop.
Save wplokal/2ce8dba2196dc4ac7d0704f582644ed1 to your computer and use it in GitHub Desktop.
<?php
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment