//** *From https://mariushosting.com/how-to-upload-webp-files-on-wordpress/*/
//** *Enable upload for webp image files.*/
//** *支持上傳 webp 格式的圖片文件 */
function webp_upload_mimes($existing_mimes) {
$existing_mimes['webp'] = 'image/webp';
return $existing_mimes;
}
add_filter('mime_types', 'webp_upload_mimes');
//** * Enable preview / thumbnail for webp image files.*/
//** *支持預覽 webp 圖片的縮略圖*/
function webp_is_displayable($result, $path) {
if ($result === false) {
$displayable_image_types = array( IMAGETYPE_WEBP );
$info = @getimagesize( $path );
if (empty($info)) {
$result = false;
} elseif (!in_array($info[2], $displayable_image_types)) {
$result = false;
} else {
$result = true;
}
}
return $result;
}
add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);
在footer中添加谷歌分析代码:
/*在底部添加谷歌分析代码*/
<?php
function add_googleanalytics() { ?>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-********-1', 'yoursite.com');
ga('send', 'pageview');
</script>
<?php }
add_action('wp_footer', 'add_googleanalytics');?>
本文更新於 2020/06/23。