- This topic has 7 replies, 2 voices, and was last updated 5 years, 4 months ago by
Elvin.
-
AuthorPosts
-
November 29, 2020 at 12:01 pm #1557062
Howard
Hi:
Would this be proper code to enter WEB P image to generatepress theme editor?//** *Enable upload for webp image files.*/
function webp_upload_mimes($existing_mimes) {
$existing_mimes[‘webp’] = ‘image/webp’;
return $existing_mimes;Also: would it just be pasted on the NEXT LINE AT THE BOTTOM of theme editor and saved?
Thanks
HowardNovember 29, 2020 at 12:07 pm #1557071Elvin
StaffCustomer SupportHi,
Yes your PHP snippet is pretty close, but it seems to be missing the filter where its suppose to apply to.
Its also missing a
}to close the function which is pretty important as it can cause syntax errors.Here’s a more complete version of your code:
//** *Enable upload for webp image files.*/ 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.*/ 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);Please refer to this on how to add PHP snippets to your site – https://docs.generatepress.com/article/adding-php/
November 29, 2020 at 12:15 pm #1557080Howard
Thanks- I will just paste it to my “Code Snippets” app
Howard
November 29, 2020 at 12:18 pm #1557088Elvin
StaffCustomer SupportNo problem. 🙂
November 29, 2020 at 12:21 pm #1557095Howard
Hi
Another question
( more complicated)
How to fix:Ensure text remains visible during webfont load
Leverage the font-display CSS feature to ensure text is user-visible while webfonts are loading.I know there are code(s) ..
But where and how to apply them ( novice)
HowardNovember 29, 2020 at 12:30 pm #1557114Elvin
StaffCustomer SupportHi,
Let’s try to keep it 1 issue per topic.
That said, can you open up a new one for your other questions? Thank you. 🙂
November 30, 2020 at 8:01 am #1558700Howard
Hi: This code does not seem to work when put into CODE SNIPPETS
//** *Enable upload for webp image files.*/
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.*/
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_imageNovember 30, 2020 at 3:10 pm #1559386Elvin
StaffCustomer SupportHi,
This part seems to be missing some codes.
... add_filter(‘file_is_displayable_imageYou have to add the function name(
webp_is_displayable), priority (10) and # of accepted args(2).add_filter('file_is_displayable_image', 'webp_is_displayable', 10, 2);Also, be mindful with smart apostrophe/curly quotes
‘. It doesn’t work if you use that, straight quote should be used'. -
AuthorPosts
- You must be logged in to reply to this topic.