ahmedkaludi / amp-theme-framework

Start Creating an AMP theme in minutes - This is a default / boilerplate theme, you can use this, modify and make one your own.
https://ampforwp.com/amp-theme-framework/
75 stars 35 forks source link

Get AMP Content #20

Open hmaesta opened 6 years ago

hmaesta commented 6 years ago

amp_content() is the replacement of the_content() – but what is the replacement for get_the_content()?

I lookup on AMP for WP code and found several references to get_amp_content(), but that function does not work when applied on a theme.

On WordPress I use a function to insert specific code after third paragraph. It's very simple and I need the same on AMP. How can I do it?

<?php
        $paragraphAfter = 3; // display after the X paragraph
        $content = apply_filters('the_content', get_the_content());
        $content = explode("</p>", $content);

        for ($i = 0; $i < count($content); $i++) {
                if ($i == $paragraphAfter) { 
                        echo "<div>Sign up and receive our newsletter!</div>";
                }
                echo $content[$i] . "</p>";
        }
?>

I can't use amp_content() since it prints data on screen, not just gets it.