Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. /* Takes the_content as input and does a string replace to convert
  4. standard img tags into amp-img tags with an optional layout argument.
  5. If no layout type is supplied it defaults to responsive. */
  6. function ampImageConverter( $html, $layout = 'responsive' ) {
  7.  
  8. // Preserve formatting from the post content
  9. $html = wpautop($html, true);
  10.  
  11. // Replace img tags with amp-img tags and add in the layout type
  12. $html = str_ireplace( '<img', '<amp-img layout="'.$layout.'"', $html );
  13.  
  14. // Add closing tags
  15. $html = preg_replace( '/<amp-img(.*?)>/', '<amp-img$1></amp-img>', $html );
  16.  
  17. return $html;
  18. }
  19.  
  20. ?>
  21.  
  22. <?php $amped_content = ampImageConverter(get_the_content()); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement