Last active
January 2, 2016 00:49
-
-
Save johnregan3/8225770 to your computer and use it in GitHub Desktop.
Add Support for Featured Images in you WordPress theme. Requires CSS like ".vertical-image { float:left; }" to work correctly.
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 | |
/** | |
* Add support for Vertical Featured Images | |
*/ | |
if ( ! function_exists( 'mytheme_vertical_check' ) ) : | |
function mytheme_vertical_check( $html, $post_id, $post_thumbnail_id, $size, $attr ) { | |
$image_data = wp_get_attachment_image_src( $post_thumbnail_id , 'large' ); | |
//Get the image width and height from the data provided by wp_get_attachment_image_src() | |
$width = $image_data[1]; | |
$height = $image_data[2]; | |
if ( $height > $width ) { | |
$html = str_replace( 'attachment-', 'vertical-image attachment-', $html ); | |
} | |
return $html; | |
} | |
endif; | |
add_filter( 'post_thumbnail_html', 'mytheme_vertical_check', 10, 5 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment