Created
February 15, 2017 17:19
-
-
Save morgyface/89817123cd550fc134c59bb835c86ea1 to your computer and use it in GitHub Desktop.
WordPress | Portrait or Landscape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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