Shylock Adsense Plugin – Hack To Avoid Smart Pricing

| Created: January 24th, 2008
Adsense Smart Pricing 43 Comments

In my last post, I talked about Adsense Smart Pricing and how blogs can avoid it by only showing ads to search engine visitors.

One option for WordPress is the Who Sees Ads plugin, which has the ability to do this. I prefer the Shylock Adsense plugin for the reasons given in my last post: automatic placement of ads; no need to enter placeholder in each post; easy to move ads from, say, top right to top left, etc.

The problem with Shylock Adsense is that although it can show ads on old posts only (mostly search engine traffic), there is no option to show ads only to search engine traffic. I really wanted this functionality, so I added a few lines of code to the plugin to enable it. In this post I explain how to do it.

Note: If you make these changes, you will lose some clicks and a lot of impressions. If you are currently smart priced, these changes should help fix that (after about a week), so you are likely to earn more. If you are not smart priced, you may actually lose money from these changes, although it safeguards you from the danger of being smart priced in future. Read my last post about Adsense Smart Pricing and blogs for a better understanding of the issues here. For my site, I’ve concluded that I wasn’t already smart priced. I do not seem to be losing any clicks, but your site may be different.

Hacking Shylock Adsense ONLY

If you are only using Shylock Adsense to show ads, then this section is for you. If you have Adsense in other places, such as the sidebar, skip this section and continue to the Hacking Shylock Adsense And Sidebars section.

First, edit the shylock_adsense.php file which comes with the plugin. Look for the following code (on line 325 in version 1.2):

[php]function shylock_adsense_filter($content){
global $id,$user_level;
$output = $content;[/php]

and replace it with:

[php]function scratch99_fromasearchengine(){
$ref = $_SERVER[‘HTTP_REFERER’];
$SE = array(‘/search?’, ‘images.google.’, ‘web.info.com’, ‘search.’, ‘del.icio.us/search’, ‘soso.com’, ‘/search/’, ‘.yahoo.’);
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
}

function shylock_adsense_filter($content){
global $id,$user_level;
$output = $content;

if (scratch99_fromasearchengine()) {[/php]

Then go down to about line 364 and look for:

[php]return $output;[/php]

and replace it with:

[php]} return $output;[/php]

Upload the edited file to the wp-content/plugin directory on your server, overwriting the original file.

If you experience any problems, simply upload an unmodified version of the shylock_adsense.php file, replacing the one you’ve changed.

Shylock Adsense will now only show ads to search engine visitors. Any existing limitations will still be in place, but there is no longer any need for them – if the plugin is set to show ads after a certain number of days, you should change this so they are shown immediately.

Note: The scratch99_fromasearchengine function is based on the ‘only show search engine’ functionality from the Who Sees Ads plugin.

Hacking Shylock Adsense AND Sidebars

Note: If you only show ads using Shylock Adsense, the previous section is for you, NOT this one.

I display ads in my sidebar, as well as in the post body. There is little point in hacking Shylock Adsense so that ads only appear to search engine traffic in the post body, if regular visitors can see them in the sidebar! Therefore, I came up with a solution to restrict ads in both places.

If we are going to use it from multiple places, the best place for the function checking if visitors are from a search engine is not in the Shylock Adsense plugin. What if we stop using the plugin in future and disable it? Then the function will stop working in other places, such as the side bar. I decided to place this function in the functions.php file in my theme folder.

Note, this is not perfect, as the functionality will be lost if the theme is changed.

1. Functions.php

Go to the wp-content/theme/yourtheme folder (where yourtheme is the name of your theme) and make a copy of the functions.php file (in case things go wrong). Then edit the file, go to the very bottom and replace:

[php]?>[/php]

with:

[php]function scratch99_fromasearchengine(){
$ref = $_SERVER[‘HTTP_REFERER’];
$SE = array(‘/search?’, ‘images.google.’, ‘web.info.com’, ‘search.’, ‘del.icio.us/search’, ‘soso.com’, ‘/search/’, ‘.yahoo.’);
foreach ($SE as $source) {
if (strpos($ref,$source)!==false) return true;
}
return false;
} ?>[/php]

Upload the edited file to your theme directory on your server, overwriting the original file.

2. Shylock_adsense.php

Edit the shylock_adsense.php file which comes with the plugin. Look for the following code (on line 325 in version 1.2):

[php]function shylock_adsense_filter($content){
global $id,$user_level;
$output = $content;[/php]

and replace it with:

[php]function shylock_adsense_filter($content){
global $id,$user_level;
$output = $content;

if (function_exists(‘scratch99_fromasearchengine’)) {
if (scratch99_fromasearchengine()) {[/php]

Then go down to about line 364 and look for:

[php] return $output;[/php]

and replace it with:

[php] } } return $output;[/php]

Upload the edited file to the wp-content/plugin directory on your server, overwriting the original file.

If you experience any problems, simply upload an unmodified version of the shylock_adsense.php file, replacing the one you’ve changed.

3. Sidebar Widget

To do this, you need to have a widget with can execute php code. I use Otto’s ExecPHP plugin, but there are others available.

If you don’t have a plugin which can do this, download ExecPHP and install it. This will add a PHP Code 1 widget to the Presentation – Widgets page in the Admin area. Drag this widget to wherever you’d like the ads to appear, click on the configure icon and enter the following into the text box:

[php]<?php if (function_exists(‘scratch99_fromasearchengine’)) {
if (scratch99_fromasearchengine()) { ?>
INSERT YOUR ADSENSE CODE HERE
<?php } } ?>[/php]

replacing INSERT YOUR ADSENSE CODE HERE with your Adsense code.

Close the text box, Save Changes and you’ll now have ads which appear in the sidebar for search engine visitors only.

4. Other Places

Although I’ve done this in a sidebar widget, the same code should work equally well in sidebar.php – or for that matter, wherever you want to use it (maybe single.php or index.php).

Testing The Changes

This applies to both hacks above. You should no longer be able to see Adsense on your site when you visit it as you normally do. Now you need to visit your site via a search engine to see if the ads appear.

You could do this by searching for your site name or url, or you could search for a relatively obscure phrase from one of your posts, contained in quote marks (eg “I’ve concluded that I wasn’t already smart priced”).

Once you find one of your posts in the search results, click it, go to your site and see if ads appear. If they do, you’ve hacked the plugin successfully.

But Wait There’s More

While this post has been written from the perspective of serving Adsense ads to search visitors only, you could use this technique to show anything to search engine visitors – other ads, custom messages, you name it…

Final Thoughts

This hack should help you avoid being smart priced by Adsense. I hope you find it of use.

I’ll be contacting the author of Shylock Adsense to see if this functionality can be added to the plugin in future. In my view, this would be a logical extension to what is already a great plugin, especially as more people become aware of Adsense Smart Pricing.

43 responses on “Shylock Adsense Plugin – Hack To Avoid Smart Pricing

  1. April - Of Scotland

    That’s a great idea. I’m going to bookmark this page and come back to it after I’ve had my beauty sleep. I know that adsense still works, it just depends on the visitor you are attracting.
    April

  2. Stephen Cronin Post author

    Pain and Jan, thanks for stopping by.

    April, Thanks. Yes it definitely depends on the type of visitors you get. There are quite a few different factors to being successful with Adsense, this is just one of them. By the way, you’ve got some really nice photos on your site – I love Scotland.

  3. RT Cunningham

    An excellent hack, Stephen. I hacked it once myself, but for different reasons. If I switch back to using this plugin, instead of WSA, I’ll definitely be using this hack.

  4. PokerStars Marketing Code

    It definitely sounds good…I’m not very “techy” though but I will give it a shot. Thanks

  5. Stephen Cronin Post author

    RT, Thanks. Sorry about the delay in responding. I live on a university campus. It has become a ghost town because everyone’s gone home for the Spring Festival – even my ISP! No access at home now and limited access at work. 🙁

    I remember your post on hacking Shylock Adsense. In fact, if you google “Shylock Hack” (without the quote marks), your post is number 1 and my post number 3 (with BlogCatalog page referencing my post at number 2). Interestingly, you’re number 1 for “Shylock Adsense hack”, but I’ve slipped to number 4 and it’s my introduction post, not this post. Weird!

    PokerStars, I hope it works for you…

  6. K-IntheHouse

    Hey Stephen,

    After having this in my to-do list, I finally took the plunge and implemented in both our blogs so that we display Adsense only to search engine traffic.

    Our CTR before this was anywhere between 1% – 4%. Today, in ShanKri-la the CTR has gone up atleast 4 times including the value of clicks. I didn’t expect to see such a difference the very next day. I don’t think it’s a coincidence but it’ll be interesting to see how much of a difference it makes overall this week. I haven’t had a click yet in spicytasty.com yet, so I can’t comment on that right now.

    Either way, I wanted to thank you for this awesome hack as I prefer Shylock Adsense over the others too.

    On another note, is there a way to use your iFrame widget plugin besides the sidebar widgets, for example using your function in theme template elsewhere.

    Cheers!

  7. Stephen Cronin Post author

    RT, Thanks – I’ve fixed it up now.

    Hi K, wow – that is a quick improvement. I’d be interested to hear if that’s maintained. Let me know how it goes!

    As for the IFrameWidgets plugin, there’s no way to use it outside of the sidebar at the moment, but I’m planning on creating a solution in future. Just when I’ll get to it is another matter – I still haven’t rebadged the current version as v1.0 and ‘released it’ (ie added it to the various lists of plugins). I’m guessing it will be about a month’s time (after Chinese New Year is out of the way).

  8. BizGiftGuru

    I better bookmark this page, so when the time comes and start running the ads I do it the right way …

  9. Zath

    This is a great and simple modification to make to your blog, from the testing I’ve done from various search engines and other sources, it displays just as it should – I’m interested to see how that affects my CTRs and income.

    Thanks for a really cool addition to my website, much appreciated!

    1. Stephen Cronin Post author

      Zath, Thanks… I hope it helps with CTR and income – if you have time, I’d love to hear how it goes…

      1. Zath

        Thanks very much for this Stephen, I can confirm that after 2 weeks of testing this out, that it really does help with increasing CTR and the CPC seems to be more consistent.

        I have just one suggestion to improve this – is there anyway that ads can be shown to search engine visitors beyond the first page that they view? I’m guessing that would involve too much tracking as opposed to just looking at the origin of a visitor?

        Thanks for a great piece of coding and I’ll probably put it on my other sites too following this experiment.

  10. Fabian

    Thanks a lot! I was searching this modification but didn’t found it! Now I can modify the plugin and use it!

  11. Mark

    Hey Stephen!

    Wow, what a post you have here! I have a few blogs that use Adsense, so I’ll be sure to give this one a try.

    Stumbled!

  12. Rhys@ WEBlog

    Hey Stephen – You are a genius: This is real magic and just what I was searching for, a method of detecting Search Engine clients. I married two of your bits of code above, and then I “include” this code as inc_adsense.php anywhere I like and Viola, Google ads appear or hide as required.

    See a working in the sidebar top here weblog.biznz.net – and all much easier than installing the plugin – it only works on WordPress anyway.

  13. Shaun @ Make Money

    Personally, I prefer to edit the code myself to optimize the adsense placings. Top left part of the post gets the highest CTR, so that’s where I usually put it. Do you get higher CTRs when you manage it your way?

  14. chi@Chrome Browser

    Good post. I do have one wordpress blog I’m developing and I do expect tons of repeat visitors to the forum. Wish they had the same plugin for vbulletin or phpbb forums. I think sites with forums get the most repeat visitors and could really get you smart priced in a hurry. Anyhow thanks for the hack.

  15. Tom@Make Money Online

    Hi Stephen,

    Does the Adsense preview in the plugin count as an impression. If so, how do we modify the plugin to remove the preview?

    By the way, there’s a small change in the code for the current plugin. Instead of “shylock_adsense_filter” it should be “whydowork_adsense_filter”

    Thanks!

  16. jeff@High yield certificate of deposit

    The shylock hack is a good one. Thanks for figuring it out it saves everyone alot of work. This should help people earn more from adsense.

  17. Carbon Poker Rakeback

    Wow, this is pretty cool stuff. Thanks for the info and I’m posting a linkback to this page. I’m just now getting into this stuff, but so far so good. thanks!

    LINK REMOVED: because of failure to use KeywordLuv syntax (name@keywords)

  18. Bailey@Rakeback

    This is a great! From the testing I’ve done with various search engines it displays just as it should – I’m interested to see how that affects my CTRs and income.

    Thanks for a really cool addition to my website, much appreciated!

  19. Expert@Make Easy Money On Internet

    I’m using adsense to make money on my blog, but I’m also trying my luck in affiliate marketing, it seems though it really works out well.

  20. jaydee@wedding photographer sussex

    Great instructions Stephen. Any idea if Shylock updated his plugin? If not maybe its time for you to create an alternative that does this out of the box?

  21. Rake

    This is a great modification to make to your blog.
    Thanks for a really cool addition to my website, appreciated.

  22. Marshal@downloadhacks

    Nice instructions over there, but is it allowed or will google ban ur adsense account

  23. Charles

    Oh man. This is sweet. I used to be an idiot when it came to php, but now I should be able to config this all up.

  24. david@wpsitelaunch.com

    Good question, since it’s been roughly a year, what’s googles take on this plugin? and are there any updates yet?

  25. Paul Skinner

    Great little hack and something i will find very useful, going to give it a try and see what happens.

  26. Rusli Zainal

    Great job Stephen ! This is what i’ve been looking for 😀

    Thanks a lot dude 😉

  27. Steve Bonanno

    Very good html code. I use him on mys site. Thanks you a lot I love this article and for this I will share on my friends!

  28. Darrin Benner

    I have tried all the above ads network.. Qadabra was the best among all but they have started the new scam of ignoring all Asian traffic.. I tried many other networks but finally I have found the best among all and it is the Propeller Ads network, which is basically a network from UK. It has been paying me $10-$15 per day for my 3000-4000 daily visitors, even-though I have just posted 3 ads on my site.

  29. Dream Market

    I had tried using media.net , but their RPM is low but good customer support. Adsense is the best one . Media.net and Chitika also good , I had received payments from them.