doubo1883
doubo1883
2017-09-03 22:53
浏览 109
已采纳

如果浏览器使用get_the_post_thumbnail()支持它,请获取webp图像

So I would like to implement webp to a website. Currently im using get_the_post_thumbnail() function to get the post featured image. Is there a way to get the webp version of the image using this function.

I have tried using the wp-webp plugin but it does not work.

Cheers

图片转代码服务由CSDN问答提供 功能建议

所以我想将webp实现到网站。 目前即时使用 get_the_post_thumbnail()获取帖子特色图像的功能。 有没有办法使用此功能获取图像的webp版本。

我尝试使用 wp-webp插件但不起作用。

干杯 \ n

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanliao6789
    duanliao6789 2017-09-04 04:01
    已采纳

    Ok the only way I can think of getting around this problem is to check the broswer and serve up a .webp image if the browser supports it by replacing the file extention with .webp

    $postId = $post->ID;
    $patterns = array("/.jpg/", "/.jpeg/", "/.png/");
    $thePostThumbUrl = get_the_post_thumbnail_url($postId, array(768,768));
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') || strpos($_SERVER['HTTP_USER_AGENT'], 'OPR/') || strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Edge')) 
        $thePostThumbUrl = preg_replace($patterns, ".webp", $thePostThumbUrl);
    
    点赞 评论

相关推荐