admin管理员组文章数量:1289528
I want to encode images in base64 for better solution to SEO proposes, I am fix some issues in audit and it say to use new image formats then load images as default like <img src='path/to/image.jpg'/>
so on my research I found that base64 encoded images solve this warning in audit.
I want to encode images in base64 for better solution to SEO proposes, I am fix some issues in audit and it say to use new image formats then load images as default like <img src='path/to/image.jpg'/>
so on my research I found that base64 encoded images solve this warning in audit.
- 1 Using a base64 encoded image src might make the warning go away, but you haven't actually solved the problem. It's still a JPG. – Jacob Peattie Commented Jul 1, 2019 at 8:31
1 Answer
Reset to default 3in your file functions.php
in your template put this funcitons
/**
* @param $path
* @return string
* @author https://github/ozzpy
*/
function imageEncode($path)
{
$path = __DIR__."/".$path;
$image = file_get_contents($path);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer($image);
return "data:".$type.";charset=utf-8;base64,".base64_encode($image);
}
/**
* @param $path
* @return string
* @author https://github/ozzpy
*/
function imageEncodePath($path)
{
$image = file_get_contents($path);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer($image);
return "data:".$type.";charset=utf-8;base64,".base64_encode($image);
}
/**
* @param $path
* @return string
* @author https://github/ozzpy
*/
function imageEncodeURL($path)
{
$image = file_get_contents($path);
$finfo = new finfo(FILEINFO_MIME_TYPE);
$type = $finfo->buffer($image);
return "data:".$type.";charset=utf-8;base64,".base64_encode($image);
}
in your html files in your template use it like:
template level:
<img src="<?php echo imageEncode("img/logo.jpeg");?>"/>
another path level:
<img src="<?php echo imageEncodePath(__DIR__."/images/slider.png");?>"/>
outside url level:
<img src="<?php echo imageEncodeURL("https://somedomain/img/image.jpeg");?>"/>
本文标签: seohow to base64 encode images in wordpress template
版权声明:本文标题:seo - how to base64 encode images in wordpress template 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741424918a2378019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论