Viewing 6 replies - 1 through 6 (of 6 total)
  • In the plugin folder:

    wp-content\plugins\accelerated-mobile-pages\themes\default

    Open up header.php and underneath <head> add the following script:

    <script async custom-element="amp-audio" src="https://cdn.ampproject.org/v0/amp-audio-0.1.js"></script>

    Open up functions.php and add this code under // Strip the styles:

    // amp_audio https://www.ampproject.org/docs/reference/extended/amp-audio.html
    function amp_audio($content) {
    $src2 = preg_match('/<audio\b[^>]*>(.*?)<\/audio>/is', $content, $resultz);
    preg_match('/<source(.*)src(.*)=(.*)"(.*)"/U', $resultz[1], $result);
    $amp_audio = array_pop($result);
    $amp_audio = str_replace("?_=1", "", $amp_audio);
    $replace = '<amp-audio width="400" height="300" src="'."$amp_audio".'">
    <div fallback>
     <p>Your browser doesn’t support HTML5 audio</p>
    </div>
      <source type="audio/mpeg" src="foo.mp3">
      <source type="audio/ogg" src="foo.ogg">
    </amp-audio>';
    
    $content = preg_replace('#<audio .*?>(.*?)</audio>#i', $replace, $content);
        return $content;
    }
    add_filter('the_content','amp_audio', 20 );

    This code will automatically solve Issue #1a (this code should replace any audio player that has <audio></audio> tag with the amp friendly tag: https://www.ampproject.org/docs/reference/extended/amp-audio.html

    Concerning Issue #1b

    In the same file “functions.php” look for :

    // amp_iframe_tag will convert all the iframe tags and will change it to amp-iframe to make it AMP compatible.
    function amp_iframe_tag($content) {
        $replace = array (
            '<iframe' => '<amp-iframe',
            '</iframe>' => '</amp-iframe>'
        );
        $content = strtr($content, $replace);
        return $content;
    }
    add_filter('the_content','amp_iframe_tag', 20 );

    replace it with:

    // amp_iframe https://www.ampproject.org/docs/reference/extended/amp-iframe.html
    function amp_iframe($content) {
    $amp_iframe = preg_match( '#<iframe .*?>(.*?)#i', $content, $matchery );
    $amp_iframe = preg_match( '@src="([^"]+)"@' , $matchery[0], $matcher );
    
    $replace = '<amp-iframe width=300 height=300
        sandbox="allow-scripts allow-same-origin"
        layout="responsive"
        frameborder="0"
        src="'."$matcher[1]".'">
    </amp-iframe>';
    $content = preg_replace('#<iframe .*?>(.*?)</iframe>#i', $replace, $content);
        return $content;
    }
    add_filter('the_content','amp_iframe', 20 );

    and don’t forget to also add this script to the header.php under <head>:

    <script async custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js"></script>

    Thread Starter harryshawk

    (@harryshawk)

    Thanks

    Plugin Author Ahmed Kaludi

    (@ahmedkaludi)

    Hey @mcfreder

    Thank you for the awesome reply! I really appreciate that you are helping Harry!

    We will be adding the Audio support in the next week’s update!

    Regards,
    Ahmed

    Thread Starter harryshawk

    (@harryshawk)

    Ahmed, if I wait until next week would I still have to make some or all of the changes manually.. is it worth waiting 🙂

    Thanks

    You are welcome guys! I made youtube/flash object video stripping tag to amp friendly if you would like me to share it too.

    Plugin Author Ahmed Kaludi

    (@ahmedkaludi)

    @mcfreder Sure, I’d love to look at the code. Anything that improves is good.

    Thanks,

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘New Issues’ is closed to new replies.