• Resolved hmaesta

    (@hmaesta)


    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor ampforwp

    (@ampforwp)

    Hi Hmaesta,

    I’d like to inform you that we use amp_content() and ampforwp_modify_the_content.

    You can achieve this by using our Advanced AMP Ads and set the Ads in multiple Positions as per your requirement.

    Thread Starter hmaesta

    (@hmaesta)

    Hello @ampforwp.
    Thank you for your help.

    “Advanced AMP Ads” is very useful, but since I need to replace some parts of the content (specific for mobile), it doesn’t solve all my problem.

    I could achieve my goal using your tip.

    Replace
    $content = apply_filters('the_content', get_the_content());
    by
    $content = $this->get( 'post_amp_content' );

    Plugin Contributor ampforwp

    (@ampforwp)

    Hi Hmaesta,

    You’re welcome.

    Thanks for updating me on this.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get AMP Content on Theme’ is closed to new replies.