RSS feed validity and Google Adsense

I want to use Google Adsense code snippets in my blog posts, so in my single.php.
However, when I do so, then my RSS feed becomes invalid because of the javascript code in the content and the feed won’t be updated anymore.

Is there ANY way to fix this?

Read More

I still have the Google Adsense code in the sidebar where it’s not causing any issues.

I’ve seen lots of blogs that have Google ads in their blog posts and a functioning RSS feed, so it seems to be possible, but how?
Or rather, why is it causing problems in my case?

I’ve done a looooooooot of research, but couldn’t find ANY information about this issue.
I think that means that it’s not a very common problem.
I really hope somebody can help me with this BIG problem.

Would something like this work? http://chaosinacan.com/programming/adsense-without-blocking/

For reference, here’s my website: http://zoomingjapan.com/

Here’s my feed: http://zoomingjapan.com/feed/

Thanks a lot in advance!

Related posts

Leave a Reply

1 comment

  1. Do not paste the Adsense code into the blog posts. Use a plugin instead.

    Sample Plugin:

    <?php
    /* Plugin Name: Zoomingjapan Adsense */
    
    add_filter( 'the_content', 'zoomingjapan_adsense' );
    
    function zoomingjapan_adsense( $content )
    {
        if ( is_feed() or ! is_singular() )
            return $content;
    
        $adsense = '<adense code, replace that!>';
    
        // remove all existing script elements
        $content = preg_replace("~<script[^>]*>.+</script[^>]*>~i", '', $content );
    
        return $content . $adsense;
    }
    

    Usage:

    • Change the content of the variable $adsense to whatever you need.
    • Put the file into wp-content/plugins/.
    • Activate it in wp-admin/plugins.php.

    That’s all.