-
AuthorPosts
-
January 19, 2020 at 12:19 pm #1175980
I have spent the last 2 hours trying to compress auto-created images…
The “add_filter(‘jpeg_quality’, function($arg){return xx;});” USED to work just fine (within the child theme ‘functions.php’) but I now noticed it didn’t with huge bloat on all images. I tried various image plugins such as SMUSH, Shortpixel etc. SMUSH stated images were compressed with huge savings but it was bullshit as on the server they hadn’t changed at all. And yes I had my custom image size checked, all was 100% from my side.So I’ve now managed to find a solution and would appreciated your input as to why this is. The add_filter ACTUALLY WORKS ONLY when I add to the ENFOLD’S ‘functions.php file’, and NOT my child ‘functions.php’!
What the?! Obviously I’d like to update the theme and not lose this edit. PS: as said earlier I’ve used this in my child’s ‘functions.php’ for years with success – it’s certainly a recent development as to it being defunct!
January 20, 2020 at 4:12 pm #1176339Hey fusion01,
Thank you for the inquiry.
Have you tried to adjust or increase the priority value? It probably doesn’t work because the default filter or av_return_100 function in the functions-enfold.php file overrides the new one.
If you want, you can also override the av_return_100 function directly and adjust the return value 100 to something lower.
Best regards,
IsmaelJanuary 20, 2020 at 4:55 pm #1176348Of course. Hence my issue. The custom value only works when incorporated into the theme’s functions file and is not applied when in the child functions file, the custom value is ignored within the latter.
January 20, 2020 at 4:57 pm #1176351Ok I see you mentioning the theme overriding my edit. How would one override what the theme has then done? I’d like something in my child theme. Possible?
January 21, 2020 at 12:29 am #1176519have you tried this in your child-theme functions.php:
function av_return_100(){ return 65; } add_filter('jpeg_quality', 'av_return_100'); add_filter('wp_editor_set_quality', 'av_return_100');
January 21, 2020 at 9:48 am #1176621Now that was fun! Upon adding to the child theme’s functions.php verbatim: “There has been a critical error on your website. Please check your site admin email inbox for instructions.”
- This reply was modified 4 years, 10 months ago by fusion01.
January 21, 2020 at 4:47 pm #1176828Hi,
Thank you for the update.
Can you post the error sent in your email? Did you copy the code from your email? Try to copy the code directly from the forum to avoid character conversion.
Best regards,
IsmaelJanuary 21, 2020 at 9:31 pm #1176939I did. Don’t build sites on my mobile phone.
January 22, 2020 at 10:46 am #1177104Hi,
Alright. What is the exact error? Can you post it here? Try to increase the priority value of your custom jpeg_quality filter.
Example:
function my_custom_jpeg_filter() { return 50; } add_filter('jpeg_quality', 'my_custom_jpeg_filter', 999);
The priority value of the filter above is set to 999 — default is 10. It should override those with lower priority.
Best regards,
IsmaelJanuary 22, 2020 at 1:07 pm #1177169Hi Ismael, the error I had previously posted: “There has been a critical error on your website. Please check your site admin email inbox for instructions.” Guenni007 must have pasted code with syntax error(s), I’m no code boffin though to comment further. But thanks! Your code in last post works perfectly, I can see that 50 value applied! You’re the man, thanks again!
January 22, 2020 at 1:34 pm #1177178i have no errors on that before:
Enfold is managing this in functions-enfold.php line: 2318
(newest Enfold 4.7.2 )if( ! function_exists( 'av_return_100' ) ) { /** * Sets the default image to 100% quality for more beautiful images when used in conjunction with img optimization plugins * * @since 4.3 * @added_by Kriesi */ function av_return_100(){ return 100; } add_filter('jpeg_quality', 'av_return_100'); add_filter('wp_editor_set_quality', 'av_return_100'); }
you allways can replace an existing parent function if it is introduced by
if( ! function_exists(…
in the child-theme functions.php.
so i only used the existing function : av_return_100January 22, 2020 at 1:40 pm #1177180Hi there, the code you provided was copied and pasted verbatim and caused a fatal error when utilised within the functions.php file within the child theme folder. I’m aware of Enfold setting a 100 value, thanks.
January 22, 2020 at 6:08 pm #1177243there must be a different error. This is a fundamental behavior of WordPress itself.
If there is a “Pluggable-Function” used – and this is allways the case if it is built via :if (!function_exists('my_parent_theme_function')) { function my_parent_theme_function() { // Code of your pluggable function } }
you can allways override the function this way (without the if-clause) in child-theme functions.php with :
( because – child theme functions are being executed first in WordPress)function my_parent_theme_function() { // Code of your pluggable function }
so maybe you are willing to post your whole child-theme functions.php here – to see if there are additonal errors.
_________
a link f.e.: https://mhthemes.com/support/knb/overriding-parent-theme-functions-child-theme-tutorial/
September 3, 2020 at 4:00 am #1242964av_return_100 to change the JPEG quality no long works in Enfold Version 4.7.6.3. When I was using 4.7.3 it worked as advertised. Can someone look at this and let me know what is the work around?
Update: You need to set the priority to 999 for it to work. While this is a work around there is an error that was introduced between the two version that is preventing the function.php filter from working at default priority.
- This reply was modified 4 years, 2 months ago by Jay.
September 8, 2020 at 1:29 pm #1244292Hi,
@Jay: The theme by default sets the jpeg_quality to 100%, so we don’t need to use that filter or add it again. Please remove the filter from the functions.php file if it was added previously. And we could also use the new filters avf_jpeg_quality and the avf_wp_editor_set_quality to adjust the default quality when necessary.
Example:
add_filter('avf_wp_editor_set_quality', function( $default, $quality, $mime_type) { return 80; }, 999, 3); add_filter('avf_jpeg_quality', function( $default, $quality, $context ) { return 80; }, 999, 3);
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.