[wp-trac] [WordPress Trac] #55510: The `wp_content_img_tag` filter can appear to run twice when used to wrap image tags

WordPress Trac noreply at wordpress.org
Thu Mar 31 23:35:17 UTC 2022


#55510: The `wp_content_img_tag` filter can appear to run twice when used to wrap
image tags
---------------------------+------------------------------------------
 Reporter:  peterwilsoncc  |      Owner:  flixos90
     Type:  defect (bug)   |     Status:  assigned
 Priority:  normal         |  Milestone:  6.0
Component:  Media          |    Version:
 Severity:  normal         |   Keywords:  needs-patch needs-unit-tests
  Focuses:                 |
---------------------------+------------------------------------------
 Follow up to [53028] for #55347.

 The new `wp_content_img_tag` can be problematic if a developer wishes to
 replace an `<img />` tag by wrapping it in another tag, eg `<span><img
 /><span>` or, more likely, the `<picture />` tag.

 If an image tag appears twice or more in a posts content and none of the
 WP default changes (width and height, responsive images, lazy loading)
 then each time the filter runs the image tag will be replaced.

 The same issue will occur if `wp_filter_content_tags()` is run multiple
 times on the same blob of HTML, although in that instance the double
 wrapping will occur for all images.

 cc @pbearne

 Please see example unit tests in the follow up comment.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55510>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list