Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

WordPressで検索エンジン訪問者だけに広告を表示する方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressに長年携わる中で、一貫して成果を上げてきた戦略のひとつが、検索エンジンからの訪問者をターゲットにした広告です。

検索エンジンからの訪問者は、通常の読者よりもターゲット広告をクリックする可能性が高いようです。このような訪問者にのみ広告を表示することで、クリック率(CTR)を高め、売上を伸ばすことができる。

この投稿では、WordPressで検索エンジンからの訪問者だけに広告を表示する方法を紹介します。

How to display ads only to search engine visitors in WordPress

なぜ検索エンジン訪問者だけに広告を表示するのか?

オンラインでお金を稼ぐ方法はさまざまだが、広告を表示するのもそのひとつだ。

Google Adsenseを使用してWordPressブログに広告を表示し、ユーザーが広告をクリックすると設定された料金を得ることができます。この戦略はクリック単価(CPC)と呼ばれます。

しかし、広告のターゲットが適切なオーディエンスに絞られていなければ、より多くのクリックを得ることは難しい。そこで、検索エンジンの訪問者に広告を限定することで、広告収入を増やすことができる。

様々な研究、業界の専門家、そして私たち自身の経験から、検索エンジンからの訪問者は、他の訪問者に比べてサイト上の広告をクリックする可能性が高いことが分かっています。適切なユーザーに適切な広告を表示し、CPCを改善することができます。

この戦略は、必要なときだけ広告を表示するのにも役立つ。広告が多すぎると、気が散ってユーザーエクスペリエンスに悪影響を及ぼします。検索エンジンからの訪問者のみに広告を表示することで、WordPressサイトが広告でごちゃごちゃになることはありません。

とはいえ、検索エンジンの訪問者だけに広告を表示する方法を見てみよう。

検索エンジン訪問者のみに広告を表示

検索エンジンからの訪問者のみに広告を表示するには、WordPressサイトにカスタムコードスニペットを追加する必要があります。

これは技術的で難しく聞こえるかもしれないが、コードを編集したり開発者を雇ったりすることなくコード・スニペットを追加する簡単な方法を紹介しよう。

サイトに広告を設定していない場合は、WordPressにGoogle Adsenseを正しく追加する方法をご覧ください。

次に、WPCodeプラグインをインストールし、有効化する必要があります。さらに詳しく知りたい方は、WordPressプラグインのインストール方法をご覧ください。

WPCodeはWordPressのための最高のコードスニペットプラグインで、サイト上の任意の場所にカスタマイコードを挿入するのに役立ちます。また、すべてのコードスニペットを管理・整理することもできます。

注:このチュートリアルでは、無料で利用できるWPCode Liteバージョンを使用します。しかし、条件付きロジック、安全なエラー処理、コード・スニペット・ライブラリなど、より多くの機能を提供するプレミアム・プランもあります。

有効化したら、WordPressダッシュボードからCode Snippets ” + Add Snippetに向かう必要があります。次に、「カスタムコードを追加(新規スニペット)」オプションをクリックします。

Add custom CSS snippet

ここから、このコード・スニペットをコピーする必要がある:

$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) {
    setcookie("sevisitor", 1, time()+3600, "/", ".wpbeginner.com"); 
    $sevisitor=true;
  }
}
  
function wpbeginner_from_searchengine(){
  global $sevisitor;
  if ($sevisitor==true || $_COOKIE["sevisitor"]==1) {
    return true;
  }
  return false;
}

注意: setcookieの行で、.wpbeginner.comをあなたのサイトドメインに変更してください。

次に、WPCodeの「コードプレビュー」エリアにコードを貼り付ける必要があります。また、スニペットの名前を入力し、’コードタイプ’ドロップダウンメニューをクリックし、’PHPスニペット’オプションを選択する必要があります。

Enter custom code for search engine visitors

その後、下にスクロールしてコード・スニペットのインサーター・メソッドを選択する必要があります。

WPCodeは初期設定で「自動挿入」オプションを使用し、あらゆる場所でコードを実行します。しかし、あなたはこれを変更し、特定のページにカスタムコードを挿入したり、コンテンツの前後に挿入したり、eコマースページに表示したりすることができます。

Edit insertion method for code

別の方法として、「ショートコード」のインサーターメソッドに切り替え、手動でショートコードを入力してコードスニペットを実行することもできます。

このコード・スニペットでは、Auto Insertメソッドを使用することをお勧めします。

完了したら、上部のトグルをクリックしてコード・スニペットを有効化し、「Save Snippet」ボタンをクリックするのを忘れないでください。

Activate and save ad code in WPCode plugin

サイトのどこに広告を表示するかを選択する

次に、別のコード・スニペットを追加し、検索エンジン・ユーザーだけに広告を表示したい場所を選択する必要がある。

以下のコードをコピーするだけだ:

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

注:上記のスニペット内の「INSERT YOUR CODE HERE」をあなたのGoogle Adsenseコードに置き換えることをお忘れなく。

上記のスニペットは、最初のコードを参照として使用し、リファラーエージェントがGoogle、Yahoo、Deliciousなどを含むあらゆるタイプの検索URLからのものであるかどうかを分析する。

訪問者のブラウザーが、リファラーエージェントがあなたが指定した検索サイトからのものであると答えた場合、訪問者があなたのサイトを訪問した時から1時間、訪問者のブラウザーに「visitor」と呼ばれるCookieを保存します。

コードを追加するには、WordPressダッシュボードからCode Snippets ” + Add Snippetに移動し、’Add Your Custom Code (New Snippet)’オプションを選択するだけです。

Add custom CSS snippet

次に、上部にコードスニペットの名前を入力し、「コードプレビュー」エリアにコードを貼り付けます。

また、ドロップダウンメニューをクリックして「PHPスニペット」オプションを選択し、「コードタイプ」を変更する必要があります。

Enter code and select code type

その後、「スニペットを保存」ボタンをクリックし、「インサーター」セクションまでスクロールダウンします。

ここでは、「ショートコード」メソッドを選択する必要があります。この方法で、サイト上のどこにでもディスプレイ広告を表示するショートコードを簡単に追加することができます。

Add shortcode for display ads

ショートコードをコピーしてもいいし、メモ帳に書いてもいい。

完了したら、上部のトグルをクリックしてコードを有効化し、「更新」ボタンをクリックすることをお忘れなく。

ショートコードを追加するには、サイトのどのセクションにアクセスしてもよい。例えば、サイドバーに検索エンジンユーザーにバナー広告を表示したい場合は、WordPressダッシュボードから外観 ” ウィジェットに移動するだけです。

ここから’+’ボタンをクリックして、サイドバーエリアにショートコードウィジェットブロックを追加することができます。

Add a shortcode widget block

コピーしたショートコードを入力してください。入力が終わったら、「更新」ボタンをクリックしてください。

WordPressは、あなたが選んだ検索エンジン別広告を、これらのユーザーがあなたのサイトに初めてアクセスしてから合計1時間表示します。

このユーザーがあなたのサイトをブックマークし、そのコンテンツを気に入って1日後に戻ってきた場合、そのユーザーはあなたの常連読者とみなされ、検索エンジン固有の広告は表示されなくなる。

この投稿が、WordPressで検索エンジンからの訪問者だけに広告を表示する方法を学ぶのにお役に立てば幸いです。WordPressのSEOに関する究極のガイドや、WordPressの広告管理プラグインのエキスパートが選ぶベストプラグインもご覧ください。

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

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

28件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. THANKGOD JONATHAN says

    Thank you for sharing this method. It will really improve user experience for returning visitors.
    Please how do I make it like to only show for desktop or mobile users?

  3. Chanakya Sahu says

    Amazing guide. I didn’t know this. Now, I am interested in learning more of these customization via coding. The customizations are limitless

  4. Jiří Vaněk says

    It sounds very good, to reward regular website visitors by offering an ad-free experience when they come directly, while showing ads to visitors from search engines. Such a win-win solution, where one can pamper regular users a bit more and essentially give them a certain bonus. It’s a great idea to display ads based on the referrer and where they came from, although I haven’t implemented Google Ads on the website yet. Nonetheless, I’ll definitely consider this approach, especially in terms of the benefit it brings to regular users.

  5. Ralph says

    This is really interesting idea! Thanks to this method we can potentially lower the number of impressions and at the same time increase CTR. At least in theory…
    Can this affect Google Ads in such way it will increase our CPS and/or CPM and make us more money?

  6. Douglas Negreiros Ferreira says

    Would be great setting a shortcode for this, then you can set it on a widget or in any post/page…

    Nice piece of code brow!

    • WPBeginner Support says

      We’ll certainly consider a method for that the next time we review this code :)

      管理者

    • WPBeginner Support says

      Your cache would show users the standard version of the site as that is what it would normally have saved for most users

      管理者

  7. Debajyoti Das says

    Can I face a google penalty if I disable “facebook comments widget” or any widget section of my WP site for search visitors…

    PS: You can add .bing. to your code.

  8. Kaushik Biswas says

    I’ve used this for a while. It also works in blogger blogs. But the problem is, if the ads aren’t shown, then either that space has to be collapsible or some other ad or image should be shown, or else, the ad space looks blank.

  9. Andrew Sylvester says

    This is a really cool idea, but its biggest drawback is that it won’t work properly if you’re using any sort of WP cache plugin (as most are, or should be!).

    I took the concept and reworked it with JavaScript instead, but I wonder if there’s a better way…

      • Sam Su says

        I am not if my ads are showing. I have try this code but I don’t have other computer to preview my ads. Right now it is not showing even if I browse it coming from Google search engine.

  10. Robert says

    Great idea lowering impressions whilst increasing click-throughs can only help your earning potential.

    A nice simple piece of code which is easily integrated.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。