Img Tag Override to Amp-Img
Jamroom Developers
I have tried adding this code to my AMP module's include.php, but it is not working. Can someone spot the problem?
function ampify($html='') {
# Replace img, audio, and video elements with amp custom elements
$html = str_ireplace(
['<img','<video','/video>','<audio','/audio>'],
['<amp-img','<amp-video','/amp-video>','<amp-audio','/amp-audio>'],
$html
);
# Add closing tags to amp-img custom element
$html = preg_replace('/<amp-img(.*?)\/?>/', '<amp-img$1></amp-img>',$html);
# Whitelist of HTML tags allowed by AMP
$html = strip_tags($html,'<h1><h2><h3><h4><h5><h6><a><p><ul><ol><li><blockquote><q><cite><ins><del><strong><em><code><pre><svg><table><thead><tbody><tfoot><th><tr><td><dl><dt><dd><article><section><header><footer><aside><figure><time><abbr><div><span><hr><small><br><amp-img><amp-audio><amp-video><amp-ad><amp-anim><amp-carousel><amp-fit-rext><amp-image-lightbox><amp-instagram><amp-lightbox><amp-twitter><amp-youtube>');
return $html;
}