Skip to content

Instantly share code, notes, and snippets.

@royce002
Created March 9, 2020 18:52
Show Gist options
  • Save royce002/4af45019d094f2625780f95a4cadc13f to your computer and use it in GitHub Desktop.
Save royce002/4af45019d094f2625780f95a4cadc13f to your computer and use it in GitHub Desktop.
Little snippet that fetches an image attachment's caption in WordPress.
<?php
function get_caption_directly($atts = array()) {
// set up default parameters
extract(shortcode_atts(array(
'id' => '52',
), $atts));
return wp_get_attachment_caption( $id );
}
add_shortcode('get_caption', 'get_caption_directly');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment