Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created April 15, 2020 20:22
Show Gist options
  • Select an option

  • Save nfsarmento/8d27c3b7bc8b426dfd163319e3d2037f to your computer and use it in GitHub Desktop.

Select an option

Save nfsarmento/8d27c3b7bc8b426dfd163319e3d2037f to your computer and use it in GitHub Desktop.
WordPress image orientation detection
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