Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Last active July 9, 2016 01:54
Show Gist options
  • Save hellofromtonya/08115780f074bb6092231b97040fa88b to your computer and use it in GitHub Desktop.
Save hellofromtonya/08115780f074bb6092231b97040fa88b to your computer and use it in GitHub Desktop.
Same function refactored using the "Return Early Pattern" - now when the conditions will not let the function continue, we get out of the function right away
function genesis_do_post_image() {
if ( is_singular() || ! genesis_get_option( 'content_archive_thumbnail' ) ) {
return;
}
$img = genesis_get_image( array(
'format' => 'html',
'size' => genesis_get_option( 'image_size' ),
'context' => 'archive',
'attr' => genesis_parse_attr( 'entry-image', array ( 'alt' => get_the_title() ) ),
) );
if ( empty( $img ) ) {
return;
}
genesis_markup( array(
'html5' => '<a %s>',
'xhtml' => '<a href="' . get_permalink() . '" class="entry-image-link" aria-hidden="true">',
'context' => 'entry-image-link'
));
echo $img . '</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment