I'm looking for some help with replacing YouTube embed codes with something that can be used with AMP pages https://www.ampproject.org/
Example, we would like replace this:
<iframe allowfullscreen="" frameborder="0" height="439" src="https://www.youtube.com/embed/xxxxxxxxxxx" width="780"></iframe>
with this:
<amp-youtube width="480" height="270" layout=responsive data-videoid="xxxxxxxxxxx"></amp-youtube>
Unfortunately, we can't simply replace the iframe
tag with amp-youtube
because we have other non-YouTube iframes floating around our site. To make things even more complicated, the YouTube embed codes live in our main content area as a WYGWAM field. Obviously, we'd like to also retain the video ID, illustrated above as 'xxxxxxxxxxx'
I've gotten pretty close with using Low Replace but my head can't wrap around regex. Here is the template code for our main content:
{exp:low_replace regex="yes" find='youtube_example' replace='amp_example' multiple="yes"}
{exp:ce_img:bulk max_width="780" bucket="site" hide_relative_path="yes" attributes='layout="responsive"'}
{content}
{/exp:ce_img:bulk}
{/exp:low_replace}
Any help would be much appreciated!