I usually refrain from hacking plugins. Normally, I'll send messages to the plugin authors with any needed changes, wait for the next version or find another plugin that works better. Other than a flaw in my theme causing problems, the Shylock Adsense Plugin for WordPress does what I want it to do.
Briefly, what the plugin does is allow you to place a maximum of three ads on the front, index page and then up to three ads on any single post page and any static page. It also has an exclusion feature, where you enter the post IDs, which will prevent ads from appearing on selective posts. This is very handy for keeping extra ads out of the sponsored posts. The plugin also allows you to change the ads, and the position of the ads, in older posts.
The flaw in my theme is that whenever an ad is placed on either the left or right side of an article, and the article includes a video, the video ends up either covering subsequent text or bleeding over the lower border of the post. This isn't a flaw in the plugin; it's a flaw in how my theme handles the content area of the post. I could probably fix it permanently if I knew exactly what to look for. Instead, I decided to hack this plugin.
Since I wanted my articles over seven days old to switch to an ad on the right side of the articles, I entered the necessary AdSense code in the plugin options. Of course, I knew it would cause those articles with the videos to get whacked out. I entered a single line into the plugin, under the "shylock_show_code($code_id,$content)" function and replacing the blank line (line 43) with this:
if (stristr($content, 'youtube.com/watch') and ($align == 'top_left' or $align == 'top-right')) {$code_id = '1'; $align = 'top';}
What it does is tell the plugin to use the same ad as the one I use for new posts on those specific posts. If I later add Google Video or other video sources, I can add one or more "or" conditions to the line, but so far I have only used YouTube videos. There are other ways to accomplish the same desired outcome, but I found this to be the easiest and not requiring me to edit the plugin or the theme every time I post a YouTube video.
Anyway, this is the plugin Chris from Blog-Op wanted when he wrote "Turn this into a plugin RT, and you could be onto a winner.". I'm considering whether to hack the exclusion function to be specific to the "This is a sponsored post" line, just so that I don't have to add post IDs to the plugin over and over again. Probably not, since I can use it the way it is to exclude other than sponsored posts.



