• Hi. I’ve got some shortcodes on my site that are meant to be put in the src attribute of an image. The shortcodes themselves contain attributes surrounded by single quotes (src is surrounded by double quotes).

    <img src="[my_shortcode id='1' height='200']">

    When lazy loading is enabled in Speed Optimizer, the src ends up getting cut off when the first single quote is encountered, breaking the shortcode and the image.

    <img decoding="async" class="alignleft lazyloaded" src="[my_shortcode id=" data-src="[my_shortcode" id=" 1' height="160" ]" border="0">

    I traced the issue back to the regular expressions in the Lazy_Load_Images class. Looks like they will start with either a single or double quote after the src attribute, and stop after either a single or double quote as well. I believe you can use backreferences in the regular expressions to stop at the same character you start at, for example:

    (?<!noscript\>)((<img.*?src=(["|\']).*?\3).*?(\/?>))
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Pavel Dosev

    (@pdosev)

    Hello @spartank,

    Thank you for your detailed feedback on the shortcode issue with our Speed Optimizer’s lazy loading feature. To check this further effectively, we need to replicate it on our end.

    Please submit a support ticket with all the relevant details if your website is hosted with us. This will enable us to access your site, create a staging copy, recreate the issue, and look for a solution.

    Thread Starter spartank

    (@spartank)

    HI Pavel,

    The issue is with some client’s of mine and due to this problem, it is not live anywhere.

    Even without the shortcode installed, it can be very easily replicated by throwing my above example in a draft and previewing on a site with Speed Optimizer enabled. Check the resulting image in a browser debugger and you’ll see the src attribute mangled in a way similar to my second code block.

    Plugin Support Pavel Dosev

    (@pdosev)

    Thank you, @spartank.
    I replicated the problem and forwarded it to our developers for further review. We will update the thread once we receive an update from them.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Lazy Loading Image breaks if src contains single quote’ is closed to new replies.