GoogleChromeLabs / ProgressiveWordPress

A Sample WordPress-based Progressive Web App
https://pwp.dassur.ma
Other
568 stars 94 forks source link

PWP Lazy Image plugin: Filter content on output, not on input #17

Open CybMeta opened 6 years ago

CybMeta commented 6 years ago

Hey!! I think that custom elements should replace native images elements on content output, not on content input. Actually, the content is modified and saved to database. In this way you get stuck to PWP lazy image plugin. If you want to use other lazy load solution or want to change the theme at any point in the future, you will need to rewrite all the posts content and save them again to database.

Alternative: use the_conent filter instead of content_save_pre. This way you preserve the content in the native format and you are free to switch between themes, lazy load solutions or even publishing platforms at any time:

add_filter('the_content' , 'lazify_images', 0, 1);

It can add a very little extra work in every request, but you get more freedom. What do you think?

surma commented 6 years ago

I think that was mostly me not really knowing what I was doing and fiddling until it worked :D Happy to accept PRs to improve this.

CybMeta commented 6 years ago

Ok, I will try to fill a pull request. Thank you!!