arnowelzel / lightbox-photoswipe

Integration of PhotoSwipe to WordPress
https://arnowelzel.de/wp/en/projects/wordpress/lightbox-with-photoswipe
GNU General Public License v2.0
27 stars 7 forks source link

Add content filter to process output #102

Closed arnowelzel closed 8 months ago

arnowelzel commented 8 months ago

Also see https://wordpress.org/support/topic/content-loaded-via-ajax/

It can happen, that images are not used because content is dynamically loaded via XHR requests (AJAX) while scrolling. However in this case the plugin will not be able to process the content to add the required data- properties to image links, since it adds an output buffer which is not used for this kind of request.

Instead of using the output buffer for the whole page one it is also possible to use the filter for the_content which is a callback for the post content. This filter will also be used on sites which dynamically output posts using XHR. However, the_content will only process the content not sidebars or other areas of the site. Therefore either the method needs to be configurable or if both variants are used, each image must only be processed once.

Option 1 - process whole website output:

add_action('wp_head', [$this, 'bufferStart'], 2050);

Option 2 - process only content of pages and posts:

add_filter('the_content', [$this, 'filterOutput']);
arnowelzel commented 8 months ago

Closed with a4e77812538692fc5faf5c07c44d35a1fdbc9211