Question

I found this great php code that will help me serve adsense ads only to search traffic.

I need help coding it so that if the user is not coming from search then another ad code is shown to the user.

This is the original code

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

 if (from_searchengine()) { ?>

 INSERT YOUR ADSENSE/BANNER CODE HERE

<?php } } ?>

What I am looking to do is if the user is not from search show another banner code.

Can someone help me with editing the code?

Was it helpful?

Solution

I don't think it's the best practise what you're doing but still:

<?php if (function_exists(‘from_searchengine’)) {
if (from_searchengine()) { ?>
INSERT YOUR ADSENSE/BANNER CODE HERE
<?php } else { ?>
INSERT ANOTHER AD CODE HERE
<?php } } ?>

but it looks better when you do that:

<?php
    $ad_code = "INSERT YOUR ADSENSE/BANNER CODE HERE";
    $another_ad_code = "INSERT ANOTHER AD CODE HERE";

    if (function_exists(‘from_searchengine’)) {
        if (from_searchengine()) {
            echo $ad_code;
        }else{
            // if not from search engine
            echo $another_ad_code;
        }
    } else{
        // if function doesn't exist
        echo $another_ad_code;
    }
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top