• Resolved roxer82

    (@roxer82)


    Hello,
    I need to use str_replace(‘xADDx’, ”, $content) to delete the tags I use in the content to show adds in regular pages, but I can’t find where to do that in the AMP Plugin files.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    How is the ad markup being added to the pages in the first place?

    There is no way to directly use str_replace() to replace content. It is better to use a conditional like:

    <?php if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) : ?>
        <amp-ad>...</amp-ad>
    <?php else : ?>
        ...non-AMP ad code...
    <?php endif; ?>
    
    Thread Starter roxer82

    (@roxer82)

    When I’m writing my entry in the wp editor, I just put xADDx in the middle of the content in the place I want the advertisement to be shown. That’s why I need to replace xADDx for nothing in AMP.

    Plugin Author Weston Ruter

    (@westonruter)

    If it’s in the content then you can just use the the_content filter. I don’t know the specifics of how that replacement happens to begin with, but you could this code in your theme’s functions.php:

    add_filter( 'the_content', function( $content ) {
        if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
            $content = str_replace( 'xADDx', '', $content );
        }
        return $content;
    }, 1 );
    • This reply was modified 5 years, 8 months ago by Weston Ruter.
    Thread Starter roxer82

    (@roxer82)

    I tryed that in my child functions.php and in the wp-content/amp/includes/admin/functions.php and it didn’t work.
    But I saw that in my child theme I had an “AMP” folder with footer.php and single.php.
    In single.php I changed this:
    <?php echo $this->get( 'post_amp_content' ); // amphtml content; no kses ?>
    for this:
    <?php echo str_Replace('<p>xADDx</p>', '', $this->get( 'post_amp_content' )); // amphtml content; no kses ?>
    and now it doesn’t show xADDx

    Plugin Author Weston Ruter

    (@westonruter)

    That isn’t the right functions.php file. It should be the one at the root of your theme.

    Thread Starter roxer82

    (@roxer82)

    Ok. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Replace content’ is closed to new replies.