Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Takes the_content as input and does a string replace to convert
- standard img tags into amp-img tags with an optional layout argument.
- If no layout type is supplied it defaults to responsive. */
- function ampImageConverter( $html, $layout = 'responsive' ) {
- // Preserve formatting from the post content
- $html = wpautop($html, true);
- // Replace img tags with amp-img tags and add in the layout type
- $html = str_ireplace( '<img', '<amp-img layout="'.$layout.'"', $html );
- // Add closing tags
- $html = preg_replace( '/<amp-img(.*?)>/', '<amp-img$1></amp-img>', $html );
- return $html;
- }
- ?>
- <?php $amped_content = ampImageConverter(get_the_content()); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement