shortcode get thumbnail size

I think your code is very close, try to use wp_get_attachment_image_src() instead: function thumb_medium( $atts, $content = null ) { // return wp_get_attachment_url( get_post_thumbnail_id( $post_id, ‘medium’) ); global $post; $thumb_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’ )[0]; if ($thumb_url) { return $thumb_url; } } add_shortcode(“get_urlthumb”, “thumb_medium”);

Lazyload post thumbnails

You got everything you need, simply build your own img-element like this: if ( has_post_thumbnail() ) { $class=”lazy attachment-thumbnail-400-300″; //Get thumbnail source $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘thumbnail-400-300’); $src = $thumb[‘0’]; $placeholder = “//placehold.it/400×300/eee/222/&text=+”; echo ‘<img src=”‘.$placeholder.'” data-original=”‘.$src.'” class=”‘.$class.'” />’; } Besides that, your main performance issue might be generating a new placeholder every time you want … Read more

how to display image from rss

Try using the_post_thumbnail WP function, inside your <li id=”news-single”> markup definition: <li id=”news-single”> <a href=”https://wordpress.stackexchange.com/questions/228220/<?php echo esc_url( $item->get_permalink() ); ?>” target=”_blank” title=”<?php printf( __( ‘Posted %s’, ‘my-text-domain’ ), $item->get_date(‘j F Y | g:i a’) ); ?>”> <?php echo esc_html( $item->get_title() ); ?> </a> <?php // This is the piece of code that you should add: … Read more

Show Post Thumbnail In Custom Post From Other CPT

If you want to get the post thumbnail URL, you can use get_the_post_thumbnail_url(): <?php $image_path=”images/club/” . $opposition->post_name . ‘.jpg’; // relative to the root directory if ( @file_exists( ABSPATH . $image_path ) ) { // Check the unique image first. $thumbnail = home_url( “https://wordpress.stackexchange.com/” . $image_path ); } elseif ( has_post_thumbnail( $opposition ) ) { … Read more

Use ‘medium’ size with catch_that_image() function

When the first image is a WordPress image attachment. in 3.6, there is an easier way. function get_first_image_medium_size_url($post_id) { if(!$images = get_attached_images($post_id)) return false; $first_image = current($images); if(!$src = wp_get_attachment_image_src($first_image->ID,’medium’)) return false; $medium_url = current($src); return $medium_url; } get_attached_images is available in 3.6. wp_get_attachment_image_src is available since 2.5.0 which will automatically get or scale the … Read more

Add version query tag to all images

Don’t know why you want to do it when there’s update_post_thumbnail_cache() in WordPress and set expire headers on server side. But you can try this in your functions.php: add_filter(‘wp_get_attachment_image_src’, function($img, $id, $size, $icon) { $img[0] = $img[0] . ‘?v={$some_version}’; return $img; }, PHP_INT_MAX, 4);

Image Quality Thumbnail Compression in WordPress?

(this should be a comment, but my reputation is too low) Setting jpeg_quality will not disable compression because it does not disable processing. JPEGs will be always compressed, and they are almost never lossless, not even at 100 – it does not stand for “100% original quality”. What happens here, is that WordPress’s default image … Read more