Skip to content

Instantly share code, notes, and snippets.

@kevinlisota
Last active August 29, 2015 14:22
Show Gist options
  • Save kevinlisota/b47f1835da80db3b3f4b to your computer and use it in GitHub Desktop.
Save kevinlisota/b47f1835da80db3b3f4b to your computer and use it in GitHub Desktop.
Call Jetpack_PostImages to resize thumbnails via Photon
<a href="<?php echo get_the_permalink(); ?>">
<?php
//check if Jetpack is acctive
if (class_exists('Jetpack_PostImages')) {
//get the ID of the post thumbnail image
$thumb_id = get_post_thumbnail_id();
//get the URL of the image
$img_url = wp_get_attachment_image_src($thumb_id, 'full');
//get the image alt text
$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
//if not alt text, use the title
if (empty($alt)) {
$alt = get_the_title();
}
//if there is a post thumbnail image URL
if ( !empty( $img_url ) ) {
//call Jetpack_PostImages to retreive a 350px x 200px image from Photon
$img_resize = Jetpack_PostImages::fit_image_url ($img_url[0], 350, 200);
//display the image
echo '<img src="' . $img_resize . '" alt="' . $alt . '">';
}
} else {
//fallback to WordPress post thumbnail if Jetpack not enabled
echo get_the_post_thumbnail($post->ID,'medium'));
}
?>
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment