Skip to content

Instantly share code, notes, and snippets.

@kjohnson
Created July 22, 2017 21:31
Show Gist options
  • Select an option

  • Save kjohnson/77dbc2e965a2b5d756c11e76c5d51064 to your computer and use it in GitHub Desktop.

Select an option

Save kjohnson/77dbc2e965a2b5d756c11e76c5d51064 to your computer and use it in GitHub Desktop.
Adds a shortcode wrapper for wp_get_attachment_image.
<?php
// ...
/*
* [attachment_image]246[/attachment_image]
*/
add_shortcode( 'attachment_image', 'my_attachment_image' );
function my_attachment_image( $atts, $content = false ){
if( ! $content || ! is_numeric( $content ) ) return;
$atts = shortcode_atts( array( 'size' => 'thumbnail', 'icon' => false, 'attr' => '' ), $atts );
return wp_get_attachment_image( $content, $atts[ 'size' ], $atts[ 'icon' ], $atts[ 'attr' ] );
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment