Display Adsense Ads Only to Search Engine Visitors in WordPress

If you’re an Adsense user, you might know the concept that Adsense pays high for the clicks that came from the people who visited your blog through organic or search results. This is even said and proved by many industry experts. Another interesting fact is that search engine visitors are more likely to click on your advertisements than the ones that came directly or from referring sites like Facebook, Twitter or some bookmarking sites.

Don’t Miss: How to Make Adsense Ads Responsive?

So, what if we got a chance to display advertisements only to the search engine visitors? Yes, the below code will help display Adsense ads only to the organic traffic whereas your regular visitors could not see these ads.

Display Ads Only to the Visitors from Search Engines in WordPress

Go to Appearance > Editor  > Open ‘functions.php’ file and paste the following code.

$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) {
setcookie(“sevisitor”, 1, time()+3600, “/”, “.9to5blogger.com“);

function from_searchengine(){
global $sevisitor;
if ($sevisitor==true || $_COOKIE[“sevisitor”]==1) {
return true;
return false;

Note: Don’t forget to replace .9to5blogger.com with your domain address.

Next, open the page where you wanted to display your ads (mostly single.php or sidebar.php etc…) and paste the following code at the desired point. [See: How to Display Adsense Ads inside WordPress Posts?]

<?php if (function_exists(‘from_searchengine’)) {
if (from_searchengine()) { ?>
<?php } } ?>

What the above code does is it analyzes whether the referring agent includes any type of search URL from Google, Yahoo, Delicious etc.… Let’s say, if a visitor entered your site from Google Image search, then it will store a cookie on their browser with the name “sevisitor” for 1 hour from the time they visited your site. If the same visitor has bookmarked your site and visited after that hour, then he will be treated as a regular visitor and the ads will not be shown to him.

Note: There is no problem in using this code to show or hide Adsense ads on your blog as long as you’re not making edits to your Adsense script.

This code not only works with Adsense ads. You can also use this to show banner ads or ads from other popular Adsense alternatives. If not ads, you can simply show a welcome message to your readers coming from Search engines.

Last Updated on by Radha Krishna under Wordpress Category 3 Comments



Share This Article

Get Free Email Alerts

Stay Updated with Useful Blogging Tips. Get Free Email Newsletter Updates..

And, Next Confirm Your Email Subcription


3 Comments to “Display Adsense Ads Only to Search Engine Visitors in WordPress”

  1. Great Post…Thanx For Sharing It…Keep Up The Good Work….
    Gagandeep Singh recently posted..Car Insurance Quote Pennsylvania by Pennsylvania Car InsuranceMy Profile

  2. Joe Hart says:

    This is a great idea.Never crossed my mind.As search audiences are more likely to click on ads, we can spare social media audiences from ads which are likely to turn them off.
    Joe Hart recently posted..Dental Implant CostsMy Profile

  3. Really a good and unique post bro., its simply awsm 🙂
    Rajagopal TechyLeakz recently posted..Best Remote Desktop and Screen Sharing without PC SoftwaresMy Profile

Leave your comment here:

CommentLuv badge

Unable to load the Are You a Human PlayThru™. Please contact the site owner to report the problem.

We Use & Recommend
[Bluehost - Review | Installation | Discount ] Bluehost Coupon
Free Email Alerts
Facebook Twitter Google Plus RSS Feed Email
Rate Us

Like US