Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #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!

    #1176339

    Hey 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,
    Ismael

    #1176348

    Of 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.

    #1176351

    Ok 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?

    #1176519

    have 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'); 
    #1176621

    Now 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.
    #1176828

    Hi,

    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,
    Ismael

    #1176939

    I did. Don’t build sites on my mobile phone.

    #1177104

    Hi,

    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,
    Ismael

    #1177169

    Hi 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!

    #1177178

    i 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_100

    #1177180

    Hi 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.

    #1177243

    there 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/

    #1242964

    av_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.
    #1244292

    Hi,

    @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

Viewing 15 posts - 1 through 15 (of 15 total)
  • You must be logged in to reply to this topic.