Line Breaks in IMG tags causing issues
-
Today I noticed my tag pages were not properly being parsed by the WP RETINA plugin and were missing the srcset attributes. For example:
<img src="https://images.pinkcakebox.com/big-cake1782-150x150.jpg" alt="Groom’s Bulldog Cake" data-post="2148" border="0" title="Click to enlarge Groom’s Bulldog Cake" />
In my template for tag.php I had a line break in the middle of the IMG definition (right after the ‘border=”0″‘ attribute):
<img src="<?= $post_thumbnail_img_url; ?>" alt="<?php the_title() ?>" data-post="<?echo $post->ID; ?>" border="0" title="Click to enlarge <?php the_title()?>" /></a>
Interestingly the log always showed it was being replaced:
2015-09-24 14:14:03: The img tag '<img src="https://images.pinkcakebox.com/big-cake1782-150x150.jpg" alt="Groom’s Bulldog Cake" data-post="2148" border="0" title="Click to enlarge Groom’s Bulldog Cake" />' was rewritten to '<img alt="Groom’s Bulldog Cake" data-post="2148" border="0" title="Click to enlarge Groom’s Bulldog Cake" srcset="https://images.pinkcakebox.com/big-cake1782-150x150.jpg, https://images.pinkcakebox.com/[email protected] 2x" />'
To fix, I removed the line break, flushed my cache, and the srcset appeared in the code:
<img alt="Groom’s Bulldog Cake" data-post="2148" border="0" title="Click to enlarge Groom’s Bulldog Cake" srcset="https://images.pinkcakebox.com/big-cake1782-150x150.jpg, https://images.pinkcakebox.com/[email protected] 2x" />
After further analysis of the code my best guess is there is an issue with the str_replace:
$buffer = str_replace( trim( $from, "</> "), trim( $to, "</> " ), $buffer ); wr2x_log( "The img tag '$from' was rewritten to '$to'" );
I’m not exactly clear how the $buffer is generated, but the line break could be causing the str_replace not to match. So even though the log says it was rewritten, the result in $buffer does not reflect the change.
Thanks for the great plugin and your continued support.
Jesse
- The topic ‘Line Breaks in IMG tags causing issues’ is closed to new replies.