最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Add version query tag to all images

programmeradmin3浏览0评论

I want caching all images on my site and prevent the browser download the images all times, so I would like add an version query tag to all images (for example: ?v=20160505)

How can I add this for image urls? Now I use this code to show images in my theme:

echo get_the_post_thumbnail( $thumbnail->ID, 'thumbnail' );

I want caching all images on my site and prevent the browser download the images all times, so I would like add an version query tag to all images (for example: ?v=20160505)

How can I add this for image urls? Now I use this code to show images in my theme:

echo get_the_post_thumbnail( $thumbnail->ID, 'thumbnail' );
Share Improve this question asked May 5, 2016 at 20:26 wpdanielwpdaniel 1327 bronze badges 2
  • 2 May I ask why? A image is not dinamic by definition. – cybmeta Commented May 5, 2016 at 21:41
  • @cybmeta, extremely rare but might happen (delete image, upload another under the same name. IIRC edit image can also cause that) – Mark Kaplun Commented May 6, 2016 at 8:52
Add a comment  | 

1 Answer 1

Reset to default 6

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);
发布评论

评论列表(0)

  1. 暂无评论