MicroTiny strips 'loading="lazy"' from html source Topic is solved

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
User avatar
creopard
Forum Members
Forum Members
Posts: 96
Joined: Fri Nov 10, 2017 10:25 am
Contact:

MicroTiny strips 'loading="lazy"' from html source

Post by creopard »

I'd like to add the attribute

Code: Select all

loading="lazy"
to an image in the HTML source code when editing content with MicroTiny like this:

Code: Select all

<img loading="lazy" src="uploads/images/picture.jpg" alt="text" width="50" height="150" />
However, MicroTiny always strips the part with

Code: Select all

loading="lazy"
when saving the input.
Is there a way to turn that behaviour off, so MicroTiny would keep this?
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: MicroTiny strips 'loading="lazy"' from html source

Post by velden »

I don't think you can change the behavior without 'hacking' the config file (we don't support posting hacks in this forum).

Have a look at https://www.tiny.cloud/docs/configure/c ... d_elements
and \modules\MicroTiny\templates\tinymce_config.js
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1825
Joined: Wed Feb 25, 2009 4:25 am

Re: MicroTiny strips 'loading="lazy"' from html source

Post by DIGI3 »

If you don't want to modify the tiny config, you could use the {image} tag. A generic template or udt also can work.
Less efficient approach, you could try adding data-loading="lazy" then in your content tag do {content|replace:'data-loading':'loading'} - I'm assuming tiny doesn't strip data- attributes but I haven't tested.
Not getting the answer you need? CMSMS support options
User avatar
creopard
Forum Members
Forum Members
Posts: 96
Joined: Fri Nov 10, 2017 10:25 am
Contact:

Re: MicroTiny strips 'loading="lazy"' from html source

Post by creopard »

Thank you for the suggestions!
I'd also like to avoid hacks in the config file, so I took a more "global" approach to add it to all images in the content:

Code: Select all

{$content|replace:'<img ':'<img loading="lazy" '}
which works also flawlessly :)
Post Reply

Return to “Modules/Add-Ons”