Skip to content

Instantly share code, notes, and snippets.

@maor
Created February 18, 2015 13:10
Show Gist options
  • Save maor/e2aabd7d2bbf79b2c305 to your computer and use it in GitHub Desktop.
Save maor/e2aabd7d2bbf79b2c305 to your computer and use it in GitHub Desktop.
function maor_image_proportions_classes($attr, $attachment) {
$image = wp_get_attachment_image_src( $attachment->ID, 'full', false );
if ( ! $image )
return $attr;
list( $src, $width, $height ) = $image;
$attr['class'] .= ( $height > $width ) ? ' wp-image-portrait' : ' wp-image-landscape';
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'maor_image_proportions_classes', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment