How to Display Ads Only to Search Engine Visitors in WordPress [Easy Steps]

Are you looking for ways to optimize your ad strategy? Or are you simply looking for answers or do you want to apply display ads only to search engine visitors in WordPress?

Whatever your reason is, you’ll find your queries answered here.

In this guide, we’ll show you how to set up your WordPress site to display ads only to people who find your site through search engines.

⁤So, let’s get right into it! ⁤

Why Show Ads to Only Search Engine Visitors?

Displaying advertisements on your website is a common way to make money online. One well-liked method for doing this is by using Google AdSense, which pays you when people click on the ads (also known as cost-per-click or CPC). 

But, it’s essential to target the correct audience if you want to optimize your revenue

Ad income may be greatly increased by restricting advertisements to search engine users. 

Search engine users are more inclined than other users to click on advertising, according to research, industry experts, and practical experience. 

Your chances of making money with CPC are increased if you limit the users to whom you show advertising. 

Furthermore, this method promotes a clean and user-friendly website. Too many advertisements might clog your WordPress site and distract from the user experience. 

By displaying advertising solely to search engine users, you ensure that they are only presented when they are most likely to be relevant and valuable rather than overloading your audience with too many adverts. 

Also read: How to Prevent Search Engines from Crawling Your WordPress Site

How to Display Ads Only to Search Engine Visitors

We are going to add a custom Code snippet plugin called WPCode to your WordPress website. 

The technique is simple to implement, so you don’t need any developer help.

So, on to the next step now search for the keyword in the Add Plugin, or you can download the plugin using the above link.

If you don’t know how to install the plugin then check out the guide on How To Install A WordPress Plugin.

WPCode

Once the plugin has been downloaded, simply click on Install Now > Activate.

After activation, go to your WordPress dashboard’s Code Snippets > Add Snippet menu. After that, select “Add Your Custom Code (New Snippet)“.

Add Custom Code Snippet

Copy this Code now, and insert it into the Code snippet:

<?php

// Function to identify search engine visitors

function is_search_engine_visitor() {

    $referal = filter_var($_SERVER['HTTP_REFERER'], FILTER_SANITIZE_URL); // Sanitize referer URL

    $searchEngines = array(

        '/search?',       // Google

        'images.google.', // Google Images

        'web.info.com',   // Dogpile

        'search.',        // Various (e.g., Bing, DuckDuckGo)

        'del.icio.us/search',

        'soso.com',        // Soso (Chinese search engine)

        '/search/',       // Miscellaneous

        '.yahoo.'         // Yahoo

    );

    foreach ($searchEngines as $source) {

        if (strpos($referal, $source) !== false) {

            setcookie('sevisitor', 1, time() + 3600, '/', 'your_domain.com'); // Replace with your domain

            return true;

        }

    }

    return false;

}

// Usage example (assuming you want to display ads only to search engine visitors)

if (is_search_engine_visitor()) {

    // Your code to display ads

    echo '';

} else {

    // code for non-search engine visitors (optional)

    echo '';

}

Note: Replace your_domain.com with your actual website’s domain to ensure the cookie functions correctly.

Code Type - PHP Snippet

After pasting, make sure to select Code Type as PHP Snippet; otherwise the Code won’t work.

To run a Code snippet, use the ‘ShortCode’ insertion method or Auto Insert. Ensure to click the toggle at the top to activate the Code snippet and click the ‘Save Snippet‘ button after completing the process.

Save snippet

After the Code has been uploaded, we’ll add another Code snippet and let you select the location where you want the ads to only show for search engine users.

Simple Code this Code:

<?php if (function_exists('search_engine_visitor')) {
  if (search_engine_visitor()) { ?>
    INSERT YOUR CODE HERE
<?php } } ?>

Note: Please make sure that the above snippet has your Google AdSense Code instead of “INSERT YOUR Code HERE.”

To save the code, follow the steps above and select “Insert Method” as [/] ShortCode for WordPress. This way, users can see search engine-specific ads on the chosen website section.

ShortCode

For example, Go to Appearance > Widgets in the WordPress dashboard if you wish to display banner adverts in the sidebar for search engine users.

You may add a ShortCode widget block to the sidebar area by clicking the ‘+‘ button from this point on.

Copy paste the same shortcode as above. After that’s all done, your ads will appear after some time (usually an hour).

Conclusion 

Displaying ads only to search engine visitors in WordPress can be a strategic approach to optimizing ad revenue while enhancing user experience. Targeting users actively seeking relevant content increases the likelihood of ad engagement and maximizes click-through rates. Implementing this strategy involves identifying search engine visitors through HTTP_REFERER and setting a cookie to recognize them on subsequent visits. 

With careful implementation and consideration of user experience, you can strike a balance between ad revenue generation and maintaining a user-friendly website environment.

FAQs on Display Ads Only to Search Engine

How do I identify search engine visits in WordPress?

You can identify search engine visitors in WordPress by checking the HTTP_REFERER header to see whether they originated from a search engine domain.

Is it possible to adopt this method without compromising user experience?

Yes, it is critical to achieve a balance between ad income and user experience. Limiting the quantity of adverts displayed and ensuring their relevance to the content may contribute to a better user experience.

Are there any downsides to presenting advertising just to search engine users?

One possible disadvantage is depending too heavily on search engine traffic for advertising income. If your site’s search engine rankings change or search engine traffic drops, your ad income may suffer.

Can I modify the list of search engines used to identify visitors?

Yes, you may adjust the list of search engines and their patterns to meet your individual requirements. Adding or deleting search engines from the list allows you to customize the strategy for your target audience.

Want faster WordPress?

WordPress Speed Optimization

Try our AWS powered WordPress hosting for free and see the difference for yourself.

No Credit Card Required.

Whitelabel Web Hosting Portal Demo

Launching WordPress on AWS takes just one minute with Nestify.

Launching WooCommerce on AWS takes just one minute with Nestify.