Created
April 15, 2020 20:22
-
-
Save nfsarmento/8d27c3b7bc8b426dfd163319e3d2037f to your computer and use it in GitHub Desktop.
WordPress image orientation detection
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
| function ns_single_image_filter($size){ | |
| $tn_id = get_post_thumbnail_id( $post->ID ); | |
| $img = wp_get_attachment_image_src( $tn_id, $size ); | |
| $width = $img[1]; | |
| $height = $img[2]; | |
| if (has_post_thumbnail($post->ID )){ | |
| if ($width > $height){ ?> | |
| <?php the_post_thumbnail($size, array( 'class' => "ns-landscape") ); | |
| }else{ ?> | |
| <?php the_post_thumbnail($size, array( 'class' => "ns-portrait") ); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment