Retrieving Script Embeds Before Rendering Content
-
Here is my scenario:
I have thousands of posts that contain embedded content through an obscure video platform. These specific embeds are made via <script> calls. When the AMP plugin sees these, it strips them out. But I need the video embeds on my AMP pages.
To solve this, I would like access these strings before the AMP plugin strips them out, so that I can turn them into proper AMP markup. That is, so I can turn a string like this…
<script src="https://embed.site.com/id.js?id=123"></script>…into a string like this:
<amp-iframe src="https://video.site.com/player.html?id=123"></amp-iframe>I already have the difficult part: The regex to retrieve, transform, and render the strings. But I don’t know how to architect it to actually retrieve the strings. The default AMP template way to write out post content is this:
echo $content = $this->get('post_amp_content');But by the time that runs, the <script> has already been stripped out, so I cannot run my regex to retrieve it. A possible solution might look something like this:
// run native wordpress content method... $content = get_the_content(); // now run my regex... $content = runMyRegex($content); // now make it amp... $content = makeItAmpCompliant($content); echo content;But I cannot find anything like a makeItAmpCompliant() method. Does such a thing exist?
Or maybe there’s a completely different way to do this that I am not thinking of.
Thanks for your help!
The topic ‘Retrieving Script Embeds Before Rendering Content’ is closed to new replies.