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で投稿コンテンツ内に戦略的に広告を挿入する手順を説明します。

サイトの収益化が初めての方にも、広告掲載の最適化をお考えの方にも、ユーザーエクスペリエンスを損なうことなく広告を表示するための専門的なヒントとステップバイステップの手順を提供します。

How to insert ads within your post content in WordPress

なぜWordPressで投稿コンテンツ内に広告を挿入するのか?

バナー広告やサイドバー広告は、WordPressでブログを書いてお金を稼ぐのに最適な方法です。しかし、これらは見過ごされがちです。

人々はコンテンツを読むためにサイトを訪れ、サイドバーやページの他のエリアにはあまり注意を払わないかもしれません。投稿コンテンツは訪問者から最も注目されるので、広告を表示するには最適な場所です。

それを念頭に置いて、WordPressで投稿コンテンツ内に広告を挿入する3つの異なる方法を紹介します。特定の方法にすぐに飛びつきたい場合は、以下のリンクをご利用ください:

準備はいいかい?始めよう

方法1.WPCodeを使用して投稿コンテンツ内に広告を挿入する(自動的)

投稿コンテンツ内に広告を挿入する一つの方法は、無料のWPCodeプラグインを使用することです。これは、市場で最高のWordPressコードスニペットプラグインの一つであり、トップWordPress広告管理プラグインの一つを兼ねています。

WPCodeは、WordPressサイトのページ、投稿日、ウィジェットエリアに広告を掲載するためのコードを簡単に挿入することができます。

Google Adsenseなどの第三者広告ネットワークからの広告を表示することができます。また、WordPressブログで広告を販売するのに最適な、独自のホスティング広告を表示することもできます。

開始するには、WPCodeプラグインをインストールし、有効化する必要があります。WordPressプラグインのインストール方法については、こちらをご覧ください。

有効化したら、WordPressダッシュボードからCode Snippets ” + Add Snippetにアクセスしよう。

ビルトインのコード・スニペット・ライブラリが表示されます。Add Your Custom Code (New Snippet)’オプションにマウスオーバーし、’Use snippet’ボタンをクリックして選択してください。

Choose the Custom Code option in the WPCode library to insert an ad

次に、「Add title for snippet(スニペットにタイトルを追加)」と表示されたフィールドに入力して、広告にタイトルを付ける必要がある。

タイトルは参考用なので、サイト訪問者には表示されません。

Add title for your ad code snippet in WPCode

その後、サイトに掲載する広告の種類を選ぶことができる。

一つのオプションは、Google Adsenseのようなプログラムが提供する広告コードを使用することです。

Google Adsenseコードを使用している場合は、最もパフォーマンスの高いGoogle AdSenseバナーのサイズとフォーマットに関するガイドを参照してください。

WordPressでAdSenseの収益を最適化する方法についての完全ガイドもあります。

もう一つのオプションは、自分で広告を作成することである。この方法を選んだ場合、WordPressサイトに広告を表示するためにお金を払ってくれる人からコードをもらうか、自分でコードを書く必要がある。

広告コードを入手したら、コピー&ペーストして「コードプレビュー」ボックスに貼り付けるだけです。次に、画面右側のドロップダウンリストから「コードタイプ」として「HTMLスニペット」を選択する必要があります。

Copy and paste ad code into Code Preview box

次のステップでは、「インサーター」セクションまでスクロールダウンします。選択できる主な挿入オプションは2つあります:

  • オートインサート– 広告コードは自動的に挿入され、選択した場所であなたのサイトに実行されます。
  • ショートコード– 広告コードは自動的にインサーターされません。WordPressブログの任意の場所に手動で挿入できるショートコードを取得します。

自動挿入」メソッドをクリックすると、投稿コンテンツ内に広告が自動的に表示されます。

次に、「Location」フィールドの隣にあるドロップダウンリストから「Insert After Paragraph」オプションを選択する。

Select Auto-Insert Insert After Paragraph to insert ad within post content

また、スニペットを挿入する段落数を選択するために、「挿入数」を変更することもできます。

例えば、最初の段落ではなく、2つ目の段落の後に広告を表示したい場合は、1を2に置き換えるだけです。

段落の後に広告を挿入するだけでなく、コンテンツの前後、投稿と投稿の間、抜粋の前後などの場所(WordPressの機能)に自動的に広告を表示することもできます。

Additional auto-insert locations in WPCode

WPCodeのプレミアムバージョンでは、商品の前後、お買い物カゴ、購入手続きページなど、WooCommerceの場所に広告を挿入することができます。

WPCode Proはまた、開始日と終了日を指定して広告コードスニペットをスケジュールすることができます。これは、 ホリデーシーズンやその他の期間限定プロモーションのために広告を表示するのに最適です。

次に、「端末タイプ」セクションまでスクロールダウンします。ここでは、どの端末タイプにも広告を表示させたいのか、デスクトップのみに表示させたいのか、モバイルのみに表示させたいのかを自由に選択することができます。

Choose which device types you want to display the ad on using WPCode

広告コードスニペットが自動インサートされるページや投稿を制限したい場合は、「スマート条件ロジック」セクションまでスクロールダウンしてください。

例えば、特定のページタイプやページURLで広告を非表示にすることができます。

Use WPCode Conditional to limit pages where the ad appears Logic to

広告を整理するために、「基本情報」セクションに行くことができます。

このエリアでは、タグやメモを追加して、広告コードスニペットの用途を覚えておくことができます。

Add tags to organize your ad code

また、同じ場所に複数のスニペットを表示したい場合に、スニペットの実行順序をコントロールできる「Priority」フィールドもある。

初期設定として、すべてのスニペットの優先順位は10です。しかし、あなたの広告コードを他のものより早く表示させたい場合は、優先順位を低い数字に設定するだけです。

広告の作成が終わったら、いよいよ公開しましょう。

そのためには、ページのトップに戻り、スイッチを「非有効化」から「有効化」に切り替えよう。そして、『スニペットを保存』ボタンをクリックする。

Activate and save ad code in WPCode plugin

これで完了です!このチュートリアルで紹介した「自動挿入」方法を選択した場合、広告が投稿コンテンツに自動的に挿入されます。

ショートコード’挿入方法を選択した場合、新規ページや投稿を作成するか、編集用のページを開きます。そして、投稿コンテンツ内でこの広告を表示したい場所を正確に探し、新しいショートコードブロックを作成するだけです。

次に、このブロックにショートコードを貼り付けます。ステップバイステップの説明は、WordPressでショートコードを追加する方法の初心者ガイドをお読みください。

これで、ページや投稿にアクセスすると、投稿コンテンツ内に広告が表示される。

注:Google Adsense広告を表示している場合、ページに広告が表示されるまで20~30分かかることがあります。

方法2.アドインサーターを使って投稿コンテンツ内に広告を挿入する。

もう一つのオプションは、Ad Inserterを使うことだ。これはWordPressの広告管理プラグインで、ホスティング広告とネットワークからプロバイダーされた広告の両方を表示することができる。

サイトネットワークを使用している場合は、Ad Inserterプラグインに広告コードを貼り付けるだけです。しかし、ホスティングサービスを利用している場合は、自分でコードを書くか、サイトに広告を表示するためにお金を払っている人からコードをもらう必要があります。

まずはじめに、無料のアドインサータープラグインをインストールして有効化します。WordPressプラグインのインストール方法については、こちらをご覧ください。

有効化した後、設定 ” 広告インサーター に進みます。

The Ad Inserter WordPress plugin

この画面では、それぞれのタブが異なる広告を表しています。これにより、複数の広告を作成し、サイトに掲載することができます。

投稿コンテンツ内に表示したい広告のコードをタイプインするか、コピー&ペーストします。

Insert ads within your post content in WordPress using Ad Inserter

次のステップは、この広告をサイトに掲載することだ。

1つのオプションは、ショートコードを使用して、任意のページ、投稿、またはウィジェット対応エリアに広告を追加することです。もう一つのオプションは、Ad Inserterに、この広告をすべての投稿に、3段落目以降など特定の場所に自動的に追加するよう指示することです。

この広告を自動的に投稿に追加したい場合は、「投稿」ボックスをチェックすることから始めることができます。

The Ad Inserter advert management plugin

次に、「挿入」ドロップダウンを開き、インサーターがこの広告を表示する場所を選択する必要があります。

投稿コンテンツ内に広告を挿入したいので、通常は「Before Paragraph(段落前)」、「After Paragraph(段落後)」、「Before Image(画像前)」、「After Image(画像後)」のいずれかを選択します。

Placing the ad within your WordPress post content

リストからオプションを選択した後、この広告を表示する場所を正確に入力することができます。

例えば、2つ目の段落の後に広告を表示したい場合は、次の画像にあるように「2」と入力します。

Inserting ads within your post content in WordPress

設定が完了したら、「設定を保存」ボタンをクリックしてください。

アドインサーターがこの広告を投稿コンテンツ内の選択した場所に挿入します。

Saving your ad settings

先に述べたように、ショートコードを使ってサイトにこの広告を掲載することもできる。

これを行うには、’Manual’ボタンをクリックし、’Shortcode’ボックスをチェックする。

Adding an ad to your post content using shortcode

設定が完了したら、インサーターショートコードをコピーしてください。その後、「設定を保存」ボタンをクリックして広告を保存することができます。

完了したら、このショートコードを任意のページ、投稿日、またはウィジェット対応エリアに配置する準備ができました。ステップバイステップの手順については、WordPressでショートコードを追加する方法のガイドを参照してください。

方法3.コードを使って投稿コンテンツ内に広告を挿入する(上級者向け)

WordPressの投稿コンテンツにコードを使用して広告を追加することもできます。

サイトのコードを編集することになるので、これは最も初心者に優しい方法ではない。しかし、特別な広告管理プラグインをインストールすることなく広告を作成することができます。

コードを使って広告を挿入するには、テーマのfunctions.phpファイルを開くか、コード・スニペット・プラグインを使用する。

テーマのfunctions.phpファイルを編集することなく、簡単にWordPressにスニペットを貼り付けることができるので、ここでも無料のWPCodeプラグインの使用をお勧めします。

さらに、WPCodeは、一般的なコードエラーを防ぎ、サイトの破損を防ぐためのスマートコードスニペット検証を付属しています。

そして次のコードを追加する:

//Insert ads after second paragraph of single post content.
 
add_filter( 'the_content', 'prefix_insert_post_ads' );
 
function prefix_insert_post_ads( $content ) {
     
    $ad_code = '<div>Ads code goes here</div>';
 
    if ( is_single() && ! is_admin() ) {
        return prefix_insert_after_paragraph( $ad_code, 2, $content );
    }
     
    return $content;
}
  
// Parent Function that makes the magic happen
  
function prefix_insert_after_paragraph( $insertion, $paragraph_id, $content ) {
    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );
    foreach ($paragraphs as $index => $paragraph) {
 
        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }
 
        if ( $paragraph_id == $index + 1 ) {
            $paragraphs[$index] .= $insertion;
        }
    }
     
    return implode( '', $paragraphs );
}

このコードは、投稿コンテンツの2段落目以降に広告を表示します。

他の場所に広告を表示したい場合は、次のセクションを変更するだけです:

    if ( is_single() && ! is_admin() ) {
        return prefix_insert_after_paragraph( $ad_code, 3, $content );
    }

上のサンプルコードでは、3段落目の後に広告を挿入しているのがわかります。

それができたら、広告コードをタイプインするかペーストしてください。これは、あなたの広告がどのように見え、どのように動作するかをコントロールするコードです。

このコードを$ad_codeの値として追加する。

    $ad_code = '<div>Ads code goes here</div>';

それができたら、広告を公開する準備は完了です。

これを行うには、サイト固有のプラグインを有効化するか、サイトのfunctions.phpファイルに変更を保存するか、WPCodeでコード・スニペットを有効化して保存します。

あなたのサイトにアクセスすると、広告が表示されます。

この投稿が、WordPressで投稿コンテンツに広告を挿入する方法を学ぶのにお役に立てば幸いです。また、クラシファイド広告サイトの作り方を学んだり、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

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

  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. Ashok Kumar says

    Hi,

    I added an ad just fine before my post. However, when I tried removing it, the blank white space remains. Please let me know how to fix this, my site looks terrible and i’m at my wits’ end!

    Thanks,
    Ashok

      • helper says

        fix drawAdsPlace to return the content, add simple-ads-manager.php (somewhere in the class):

        function get_drawAdsPlace($args = null, $codes = false) {
        global $samObject;

        if(is_null($args)) return ”;
        if(is_object($samObject)) return $samObject->buildAd($args, $codes);
        else return ”;
        }

        then use get_drawAdsPlace instead drawAdsPlace. (Updating plugin will kill this)

  3. Zaman says

    I have noticed that there are around three ads in each post in list25 with one ad after every the first post while two other ads randomly between the images.

    So, could you please inform how can it be achieved? Are you using the insert post ads or some manual coding for the second and third ads. If so, what is the manual code and where are you inserting it.

  4. Annastasia Taylor says

    Hi,
    “Insert Post Ads” plugin setting doesn’t work for me, when i click on settings-nothing displaying.

    Code works fine, Thanks!

    So my question is, can i repeat this action? I mean if i can insert the ads after paragraph 1 and 2.

    I tried to repeat the code, but doesn’t work : “Fatal error: Cannot redeclare prefix_insert_post_ads()…..”

    Please help

    Thanks in advance

  5. Jorge Pinto says

    Hi, its possible to use the above code with this one integrated?

    //////////////////here mobile ad

    ////////////////// here desktop ad

  6. Christian Rauchenwald says

    Great plugin BUT I’m missing one very important thing -> if I create 4 ads to be displayed after paragrahp two I should get the option to show one of them randomly…

    It would also be great to be able to define “categories” for banner, so that a poker related banner doesn’t show up in my day trading section.

  7. Arsie says

    Hi,

    For multi-author WP-blog who does not want to use plugins, can you recommend the code that I can put in the functions.php?

  8. Salud Casera says

    This one really worked for me. I removed the CSS and added some inline css and got the ad before the content, float left, etc. and it ended up exactly as I wanted it.

    You can see it here :

    Thanks for sharing.

  9. Ben Daggers says

    Quick question, what if I assigned “5” as the number of paragraph for the adsense code to appear, but the number of paragraphs in my post is only four. What will happen? Will it still work?

  10. Amanda says

    I have 2 qusestions:

    1. Is there a way to add text above an ad? For example, amazon affiliates has a banner for $3 per sign up, but they are also doing a contest in the same signup where users can win $500, I’d like to ad a note above the referral banner for sign up about the contest, is there away to do that?

    2. How can I had this to the front page?

  11. Belinda says

    Great tutorial, thanks. Is there a way for me to had the ads also show up on my homepage? I have a sticky post at the top and then my posts show up after that but this version of the posts have no ads. So ads only appear if the reader actually clicks through on a post to the individual post URL. Would be great if the ads would show also on the homepage.

  12. steve says

    What impact does this have on SEO considering there will be links to adverts within the content of the page?

  13. Aadil says

    Hello Wpbeginner,
    Really a good explanation. Really like it. However I have one question, would be really grateful if you could help me. If we use the code way,Is there a way to exclude some pages like- about, contact us etc where we dont want want the ads to appear.

  14. Antonios says

    With this plugin the ads placed in a post appear in all the other posts. How can I place an ad in one specific post, and that it won’t appear on other posts?

    I have posts related to specific services, products, and topics. I need to be able to place ads related to the specific post, and that won’t appear on other posts, because ads won’t be related to those other posts.

  15. tigaruk says

    How do i get it to only appear on posts pages using the code above, not the plugin. Currently its also appearing on my product pages.

  16. Dan Sz. says

    Is there a way to get this to work within a custom loop? For example, when showing the full content of a featured post on the home page.

  17. kristarella says

    Thanks for this. I would recommend tweaking the code slightly to add the insert at the end of a post if it is shorter than the specified number of paragraphs. This can be done with:

    $num = count($paragraphs);
    if ($num == 0 || $num < $paragraph_id) {
    return $content.$insertion;
    }

  18. Brandon says

    Is there a way I can do this but have it on last paragraph? I want to insert at bottom right of every post’s content and have text wrapped using div align=”right” which I can see in your code I can change the div ad container, but I want it on bottom. Thanks!

  19. Magic says

    Thanks for the tutorial. What would the functions.php code be if I wanted the ad to show as the second paragraph up from the “bottom” of the page (not the second paragraph from the top of the page)?

  20. Margaret Anne @ Natural Chow says

    What do I do if there is only a blank space showing up where the ad is supposed to be? I don’t have an ad-blocking software on my computer so am I doing something wrong?

  21. Josh M says

    Hi, great, simple plugin. Just wanted to make two suggestions.

    I would recommend removing the hard-coded styling for the div or add a css box in settings, so it can be positioned easier. For those wondering, remove this in insert-post-ads.php…

    style=”clear:both;float:left;width:100%;margin:0 0 20px 0;”

    A simple option (checkbox?) on the post/page to “exclude content ads” would be great as well.

  22. St3elSh0t says

    Hi Syed, could you please tell me how to add 2 ads after 1st paragraph so that there is one ad then a tab then another ad code?

    • Brandon says

      You could use the code to add to functions.php and instead of using ad code here … you could do first ad code here second ad code here

      Then edit style sheet to set sizes and alignment for .maincontainer
      .firstad
      .secondad

  23. ETphonehome says

    I’ve installed the plugin and it shows all in the preview but the ads are not shown when I publish the post. What did I do wrong? Thanks.

    • David says

      Not familiar with Adsense, could you provide an example? If I’m designing my own ad and its is a jpeg, what would the ad code be if the jpeg is called MattsAutoSales.jpeg ?? I’m used to working with print ads which usually just use the digital name for placement (MattsAutoSales.jpeg)
      Thanks for the help!

  24. WPBeginner Staff says

    An existing plugin on your site may be conflicting. We recommend deactivating all plugins except insert post ads and then activate other plugins one by one until you figure out which plugin is causing the issue. Let us know.

  25. Kim Whitley-Gaynor says

    Very helpful information! Thank you very much. What plug-in do you recommend for inserting ads into a sidebar?

返信を残す

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