How To Display Ads Only to Search Engine Visitors in WordPress 2024

Display Ads Only to Search Engine Visitors: Do you want to show targeted ads only to visitors coming from search engines?

According to our experience and many industry experts, search engine visitors are likelier to click on a targeted ad than your general readers. Simply showing these visitors ads can increase the click-through rate (CTR) and sales.

In this article, we’ll show you how to Display Ads Only to Search Engine Visitors in WordPress.

Why Display Ads Only To Search Engine Visitors?

There are various ways to make money online, and showing ads is one of them.

You can use Google AdSense to show ads on your WordPress blog and earn a placement fee when a user clicks on the ads. This strategy is called cost-per-click (CPC).

However, getting more clicks can be challenging if the ads target a different audience. Even limiting ads to search engine visitors can increase advertising revenue.

Various studies, industry experts, and our own experience show that visitors who come from search engines are more likely than other visitors to click on ads on your site. You can show suitable ads to the right users and improve CPC.

This strategy also helps ensure that ads are shown only when necessary. Too many advertisements can be disruptive and harmful to a person’s experience. By displaying these only to search engine visitors, your WordPress website will not be filled with ads.

Let’s see how you can Display Ads Only to Search Engine Visitors.

Showing ads only to search engine visitors

To Display Ads Only to Search Engine Visitors, add a custom code snippet to your WordPress website.

It may seem technical and daunting, but we will introduce you to how you can easily add code snippets without editing them or hiring a developer.

If you don’t have ads on your site, please visit our guide on properly adding Google AdSense in WordPress.

Next, you need to install and activate the WPCode plugin. To learn more, please visit our guide on how to install a WordPress plugin.

WPCode is the best code snippet plugin for WordPress, and it helps you add custom code anywhere on your site. It also enables you to manage and organize all your code snippets.

Note: For this tutorial, we’ll use the WPCode Lite version, which is free and offers even more features for business plans. However, premium plans provide more features like user intelligence, secure error addressing, code snippets library, and more.

After activation, you must go to Code Snippets » and add Snippets from your WordPress dashboard. Choose ‘Add Your Custom Code (New Snippet)’ after that.

You must copy this section of code from here:

$SE = array('/search?', '', '', 'search.', '', '', '/search/', '.yahoo.');
foreach ($SE as $source) {
  if (strpos($ref,$source)!==false) {
    setcookie("sevisitor", 1, time()+3600, "/", ""); 
function bloggingsupport_from_searchengine(){
  global $sevisitor;
  if ($sevisitor==true || $_COOKIE["sevisitor"]==1) {
    return true;
  return false;

Note: In the set cookie line, replace with your site domain.

Next, paste the code into the WPCode ‘Code Preview’ area. You’ll also need to enter a name for your Snippet, and then click the ‘Code Type’ dropdown menu and select the ‘PHP Snippet’ option.

Next, you need to select the insertion method for the code snippet.

WPCode will run the code everywhere and use the ‘Auto Insert’ option by default. However, you can change it and have the custom code appear on specific pages, before or after content, show it on e-commerce pages, and much more.

Alternatively, you can switch to the ‘Shortcode’ entry method and manually enter a shortcode to run the code snippet.

For this code snippet, we recommend using the auto-insert method.

Once you’ve done this, click the toggle above to activate the code snippet, then click the ‘Save Snippet’ button.

Choose where to show ads on your site

Next, you need to add another code snippet and select where you would like to Display Ads Only to Search Engine Visitors.

Just copy the code below:

<?php if (function_exists('bloggingsupport_from_searchengine')) {
  if (bloggingsupport_from_searchengine()) { ?>
<?php } } ?>

Note: Remember to replace ‘INSERT YOUR CODE HERE’ in the above Snippet with your Google AdSense code.

The Snippet above uses the context of the first code and analyzes whether the referrer agent is from any type of search URL, including Google, Yahoo, Delicious, and others.

If a visitor’s browser indicates that the Referrer Agent is from any search site you specify, it will store a cookie called ‘Visitor’ in their browser for 1 hour from when they visited the site.

To add code, go to Code Snippets » + Add Snippet from your WordPress dashboard and select the ‘Add Your Custom Code (New Snippet)’ option. Next, enter a name for your code snippet above and paste the code into the ‘Code Preview’ area.

You must also change the ‘Code Type’ by clicking the dropdown menu and selecting the ‘PHP Snippet’ option.

After this, click the ‘Save Snippet’ button and scroll down to the Injection section.

Here, you have to select the ‘Shortcode’ method. This way, you can easily add shortcodes to display ads anywhere on your site.

You can copy the shortcode or write it to a Notepad file.

When finished, click the toggle above to activate the code and click the ‘Update’ button.

To add shortcodes, you can head to any section of your website. For example, to show banner ads to search engine users in the sidebar, go to Appearance » Widgets from the WordPress dashboard.

You can click the ‘Instinct’ button to add a shortcode widget block to the sidebar area.

Go ahead and enter the shortcode you just copied. When you are finished, click the ‘Update’ button.

WordPress will now show these search engine-specific ads for one hour to users who have visited your site for the first time.

If this user bookmarks your site and returns a day later because he liked your content, he will be considered your regular reader and not see search engine-specific ads.

This article helped teach you how to Display Ads Only to Search Engine Visitors in WordPress. You may also want to check out our ultimate guide to WordPress SEO and our expert’s pick for the best WordPress ad management plugins.

If you liked this article, please subscribe to our YouTube channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Leave a Comment