Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Created October 17, 2018 15:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mikeschinkel/08277d1a750e0d518b3a921c3f94427a to your computer and use it in GitHub Desktop.
Example passing optional $args
<?php
/**
* @param array $args
*
* @return string
*/
function get_banner_image_html( $size = 'medium', $args = array() ){
$args = array_merge( array(
'before' => '<figure class="show__banner-image">',
'after' => '</figure>',
'empty' => ''
), $args );
$html = '';
if( !$image_id = $this->banner_image_id() ){
$image_id = $this->featured_image_id();
}
if( $image_id ){
$html = wp_get_attachment_image( $image_id, $size, false, $args );
} else {
$html = $args['empty'];
}
return $html ? "{$args['before']}{$html}{$args['after']}" : '' ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment