我使用WebP快速插件(https://wordpress.org/plugins/webp-express/)。
你能告诉我如何找到一条通往webp图像的路吗?
我的意思是类似于这个:
wp_get_attachment_image_src($attachment_id = 1, $size = 'medium_large');结果应该是
http://galina/wp-content/webp-express/webp-images/uploads/2019/12/sports-4-768x512.jpg.webp

发布于 2022-05-31 03:09:56
我写了一堂课来解决这个问题。
use \WebPExpress\AlterHtmlHelper;
class WebpExpressExtended
{
public static function background($imgId, $imgSize = 'full')
{
$img = wp_get_attachment_image_src($imgId, $imgSize)[0];
if (!$imgId || !$img) {
return false;
}
return AlterHtmlHelper::getWebPUrl($img, null);
}
}将其粘贴到functions.php或需要的文件中。
要使用它,只需调用静态方法背景($imageID、$imageSize);
echo WebpExpressExtended::background(309, 'thumbnail');https://stackoverflow.com/questions/71253853
复制相似问题