Title: webp support code
Last modified: November 5, 2023

---

# webp support code

 *  Resolved [i0n1ca](https://wordpress.org/support/users/i0n1ca/)
 * (@i0n1ca)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/)
 * Hi ulfben,
 * Thank you for this great plugin. I am replying to my old post with „webp support”.
 * In wp-jquery-lightbox.php line 176, 183, 199 please add just „|webp” after bmp,
   gif, jpg, jpeg, png.
 *     ```wp-block-code
       //Matt's version to support multiple rel values
       //https://wordpress.org/support/topic/fix-for-auto-lightboxing-links-that-contain-rel-attributes-already?replies=12
       function jqlb_do_regexp_multirel($content, $id){
       	$id = esc_attr($id);
       	$a_tag_img_regex = "/(<a[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png|webp)[^>]+)>/i";
       	if (preg_match_all($a_tag_img_regex, $content, $a_tag_matches, PREG_SET_ORDER)) {
       		foreach ($a_tag_matches as $a_tag) {
       			$new_a_tag = $a_tag[0];
       			$rel_regex = "/(rel=['\"])(?![^>]*?(?:lightbox|nolb|nobox))([^'\"]+)(['\"])/i";
       			$new_a_tag = preg_replace($rel_regex, '$1lightbox['.$id.'] $2$3', $new_a_tag);
   
       			$no_rel_regex = "/(<a(?![^>]*?rel=['\"].+)[^>]+href=['\"][^>]+\\.(?:bmp|gif|jpg|jpeg|png|webp)[^>]+)>/i";
       			$new_a_tag = preg_replace($no_rel_regex, '$1 rel="lightbox['.$id.']">', $new_a_tag);
   
       			if ($new_a_tag != $a_tag[0]) $content = str_replace($a_tag[0], $new_a_tag, $content);
       		}
       	}
       	return $content;
       }
   
   
       /* automatically insert rel="lightbox[nameofpost]" to every image with no manual work.
       	if there are already rel="lightbox[something]" attributes, they are not clobbered.
       	Michael Tyson, you are a regular expressions god! - http://atastypixel.com */
       function jqlb_do_regexp($content, $id){
       	$id = esc_attr($id);
       	$content = preg_replace('/\s+rel="attachment wp-att-[0-9]+"/i', '', $content); //remove WP 4.4 garbage
       	$pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png|webp)(\?\S{0,}){0,1}['\"][^\>]*)>/i";
       	$replacement = '$1 rel="lightbox['.$id.']">';
       	return preg_replace($pattern, $replacement, $content);
       }
       ```
   
 * Thank you!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fwebp-support-code%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Support [edanzer](https://wordpress.org/support/users/edanzer/)
 * (@edanzer)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/#post-17176609)
 * Hey there [@i0n1ca](https://wordpress.org/support/users/i0n1ca/)! After an amazing,
   long run by [@ulfben](https://wordpress.org/support/users/ulfben/), I’ve taken
   over the maintenance of this plugin. I intend to continue actively supporting
   it indefinitely. I’ll be posting some kind of announcement soon, at least here
   in the forums. 
   I’ll happily include your change in the next release, hopefully
   within the next 1-2 weeks. Thanks very much for following up on this change, 
   and for the detailed code suggestion/fix – even with line numbers :).
 *  Plugin Support [edanzer](https://wordpress.org/support/users/edanzer/)
 * (@edanzer)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/#post-17176611)
 * By the way, if you have any other outstanding feedback or suggestions please 
   feel free to share. As a new maintainer, I’m very interested right now in hearing
   feedback or suggestions from those who have been actively using the plugin.
 *  Plugin Support [edanzer](https://wordpress.org/support/users/edanzer/)
 * (@edanzer)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/#post-17176670)
 * I was working on some small changes and decided to just make the webp change 
   and push a small release. If you get a chance, please confirm webp is working
   as you’d expect. Thanks!
 *  Thread Starter [i0n1ca](https://wordpress.org/support/users/i0n1ca/)
 * (@i0n1ca)
 * [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/#post-17177087)
 * Hi [@edanzer](https://wordpress.org/support/users/edanzer/),
 * Thanks for your fast reply, I can confirm that is working now. Till now, I love
   this plugin because it’s simple and it does what it says, creates a nice image
   preview.
 * Sure, if something goes through my mind I will come back with feedback.
 * Congrats,
 * Ioan

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘webp support code’ is closed to new replies.

 * ![](https://ps.w.org/wp-jquery-lightbox/assets/icon-256x256.png?rev=3274178)
 * [LightPress Lightbox](https://wordpress.org/plugins/wp-jquery-lightbox/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-jquery-lightbox/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-jquery-lightbox/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-jquery-lightbox/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-jquery-lightbox/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-jquery-lightbox/reviews/)

## Tags

 * [webp](https://wordpress.org/support/topic-tag/webp/)

 * 4 replies
 * 2 participants
 * Last reply from: [i0n1ca](https://wordpress.org/support/users/i0n1ca/)
 * Last activity: [2 years, 7 months ago](https://wordpress.org/support/topic/webp-support-code/#post-17177087)
 * Status: resolved