문제

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' );
도움이 되었습니까?

해결책

Don't know why you want to do it when there're 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=20160505';

    return $img;

}, 10, 4);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top