Skip to content

Instantly share code, notes, and snippets.

@temsool
Created September 22, 2018 10:27
Show Gist options
  • Save temsool/62bdc238899a5a9520f45a242827c79f to your computer and use it in GitHub Desktop.
Save temsool/62bdc238899a5a9520f45a242827c79f to your computer and use it in GitHub Desktop.
Put attachment via shortcode in WordPress
function put_attachment_image($atts) {
$atts = shortcode_atts(
array(
'id' => '1',
'title' => get_the_title($atts['id']),
'alt' => get_the_title($atts['id']),
'class' => '',
'size' => 'full',
), $atts
);
return wp_get_attachment_image($atts['id'], $atts['size'], false, array('title' => $atts['title'], 'alt' => $atts['alt'], 'class' => $atts['class']));
}
add_shortcode('att-image', 'put_attachment_image');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment