RSS feed validity and Google Adsense

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.