Display thumbnail only if requested size exists

Assuming the question is about wp_get_attachment_image_src. It could be also about wp_get_attachment_link, but, although related, this analysis doesn’t includes it. Got aware of this issue answering this question: How can I view all WP generated thumbnails in Media Manager?. Refer to it to see a working code regarding the issue on this Question. And it … Read more

How to add post featured image to RSS item tag?

You could do it by adding an action to the hook ‘rss2_item’ like so: add_action(‘rss2_item’, function(){ global $post; $output=””; $thumbnail_ID = get_post_thumbnail_id( $post->ID ); $thumbnail = wp_get_attachment_image_src($thumbnail_ID, ‘thumbnail’); $output .= ‘<post-thumbnail>’; $output .= ‘<url>’. $thumbnail[0] .'</url>’; $output .= ‘<width>’. $thumbnail[1] .'</width>’; $output .= ‘<height>’. $thumbnail[2] .'</height>’; $output .= ‘</post-thumbnail>’; echo $output; });

How to Dynamically Resize WordPress Image On-The-Fly (custom field/theme option)

Re-size WordPress images on the fly using built-in WordPress functions. Use the vt_resize function to dynamically re-size WordPress images located in a custom field, featured image, uploads directory, NextGen Gallery WordPress plugin, or even an external link to an offsite image. It is very simple to use, just copy/paste the code below into your WordPress … Read more

Generate Thumbnails only for Featured Images

This function will generate an image by temporarily registering an image size, generating the image (if necessary) and the removing the size so new images will not be created in that size. function lazy_image_size($image_id, $width, $height, $crop) { // Temporarily create an image size $size_id = ‘lazy_’ . $width . ‘x’ .$height . ‘_’ . … Read more

How to get featured image’s width and use elsewhere in template?

Try the following. First, add this piece of code to the template: <?php $image_data = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), “thumbnail” ); ?> $image_data will now return an array containing the url, width, and height (function reference). To get the width, you might do this: <?php $image_width = $image_data[1]; ?> In your specific example, after adding … Read more