Support » Plugin: Imagify – Optimize your Images & Convert WebP » Please consider remove \n (new line) in \classes\Webp\Picture\Display.php

  • Resolved Mamekko


    Version 1.9.11

    Hi, I’m using webp replacement with a following setting;
    Display images in webp format on the site -> Use <picture> tags (preferred)

    However, because of 4 “\n”s inside \classes\Webp\Picture\Display.php, when an image is set inside script as a value for a key, the script doesn’t work.

    example(Google Maps API):

    position: new google.maps.LatLng(xxxxx,yyyyy),
    content: '<?php the_post_thumbnail('thumbnail'); ?>'

    When I remoce 4 “\n”s, my script works. But I don’t believe it’s a good idea to fix the problem.

    Would you please consider remove those “\n”s in the Display.php?
    Thank you for your support in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WP Media


    Hey @mamekko

    Thanks for reporting this.

    Indeed, it looks like \n will break the code executed via JS. At this moment, you can keep it this way by removing \n from the code. We are checking possibilities with our developers in order to see the best way to resolve it so will get back to you once we find solution (or have more info).


    Plugin Author WP Media


    Hey @mamekko

    I have the update.

    You can keep these \n lines until the new release as we will include it. Just in case we don’t, you will have to do each time we release until this change gets included on our side.

    Or, programmatically, you can remove these by using the imagify_buffer filter.

    This should do the job (you can add them in functions.php):

    add_filter('imagify_buffer', 'customer_remove_newlines');
    function customer_remove_newlines($buffer) {
    	return str_replace("\n", '', $buffer);

    Please note: the above filter will remove ALL newlines from the html across the whole page. If that’s a concern, you could revise the string replacement to target the specific newlines more accurately.

    Hope this helps. Let me know if you need any further assistance.

    Best Regards

    Thread Starter Mamekko


    Hi Marko, thank you for your reply and suggestion!
    The hook works well for the time being.
    Looking forward to next update πŸ™‚

    Best regards,

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Please consider remove \n (new line) in \classes\Webp\Picture\Display.php’ is closed to new replies.