Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created February 15, 2017 17:19
Show Gist options
  • Select an option

  • Save morgyface/89817123cd550fc134c59bb835c86ea1 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/89817123cd550fc134c59bb835c86ea1 to your computer and use it in GitHub Desktop.
WordPress | Portrait or Landscape
<?php
$post_thumbnail_id = get_post_thumbnail_id();
$image_attributes = wp_get_attachment_image_src( $post_thumbnail_id, 'full' );
if ( $image_attributes ) {
$width = $image_attributes[1];
$height = $image_attributes[2];
if ( $width > $height ) {
echo get_the_post_thumbnail( $post_id, 'medium', array( 'class' => 'landscape' ) );
} elseif ( $width < $height ) {
echo get_the_post_thumbnail( $post_id, 'medium', array( 'class' => 'portrait' ) );
} else {
// If we are here the width and height must be equal
echo get_the_post_thumbnail( $post_id, 'medium', array( 'class' => 'square' ) );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment