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. Manuel Graf says

    Thanks, it works for me, but I need a feature, can the magic only happen if there are more than 1500 characters in the Post? How can I do this?
    Thanks a lot!

    • WPBeginner Support says

      We do not have a recommended method for only activating if there are a certain number of characters but if we do we will look to update the article :)

      管理者

  3. Erika says

    Will the Ad Sanity allow to place external ads on an individual post only not on the entire site?

  4. George says

    Is there any way how to insert different ads after multiple paragraphs? For example AdSense ad no 1 after 2nd paragraph, AdSense no 2 ad after 6th paragraph?

    • WPBeginner Support says

      If your ad network has different ads to display then method 2 should allow for what you are wanting currently :)

      管理者

  5. Gideon says

    will this code replace the entire existing code of the theme child theme?

    The <?php start is returning error

    • WPBeginner Support says

      It will not replace your entire theme’s design. For pasting the code in your functions.php you could try removing that opening PHP tag to see if that helps solve the issue.

      管理者

  6. Oniel says

    Can you please update the plugin to be able to add the code “before” the first paragraph instead of “after” the first paragraph?

    • WPBeginner Support says

      The plugin does have the option to insert before your post content instead of after a paragraph number

      管理者

  7. Shannon says

    This is amazing, thank you so much for this. Do you know why my ad goes to the left of the post and not in the middle?

    • WPBeginner Support says

      The most common reason would be if your theme has styling that is forcing that alignment.

      管理者

  8. Karthik says

    how much time take for adsense ad display on our site once we get approved after the code placed.

    • WPBeginner Support says

      That would be a question for Adsense as they may not have ads they would currently offer for your site.

      管理者

  9. Sangam says

    Thank you, with the help of this snippet I managed to show ad after each 300 words. I just added word count instead of paragraph.

  10. Chango says

    Hello is that Insert posts ads plug in good? or does it crash the site or slow it down? I am nervous because 7 years ago I used a adsense plug in and the maker of the plug in was adding their ads on my website.

    Is this insert ads plug in good that you recommend. Does it mess with coding or slow down the site?

    thanks.

    • WPBeginner Support says

      Unless you manually add problematic code, the insert post ads plugin shouldn’t harm your site’s speed.

      管理者

  11. Arkantos says

    Works great! But I noticed it also counts the paragraphs from an embedded tweet. Is it a way to avoid that and count only text paragraphs from the content/article?

  12. Von says

    Is there a wordpress tag to have a ‘content/block’ automatically injected into the middle of my blogs.

    I’m looking for documentation (I’d seen it before). I would appreciate any help here.

    Thank you.

    • WPBeginner Support says

      For what it sounds like you’re wanting, you would want to use the recommendation from the article

      管理者

  13. Willys says

    Hi, I have just Signed up to Google adsense but I am having a problem of how to copy my Google adsense code to my website (WordPress). How can i do it?

  14. Sangam says

    I am using this code snippet in my child theme function.php to make ads appear in 3rd paragraph. But I want it to repeat after each 3 or 4 paragraph. How it can be done?

    • WPBeginner Support says

      As we state in the article, you would change the number in the code snippet to change where the ad appears.

      管理者

        • WPBeginner Support says

          If you wanted the ad to display multiple times then inside the if statement where it has: return prefix_insert_after_paragraph
          You would want a new line where you add a copy of the prefix_insert_after_paragraph with a different paragraph number

    • WPBeginner Support says

      You would need to use the site-specific plugin method and change the 2 to a 3 on line 12

      管理者

  15. Peter says

    Hi
    Only the code is showing on my post no images. The code is just lying there in the post, you won’t even notice it’s there
    What can I do to change this
    I need the banners showing in the post

    • WPBeginner Support says

      You may want to ensure you added the code with all of it’s tags correctly for your ads and didn’t skip any tags.

      管理者

  16. Ngo says

    Hello,

    Thank you for the manual code. It seems to be working for everyone but I just can’t get it to work on my site. My site is made up of only Custom Post Types. Is this why it is not working? Please what do I need to change in the code to make them display on my custom post types?

    Even ordinary widgets do not display on my site. Is there anything I can include in my functions.php to make changes display on my custom pages?

    Please help, I have tried every code on the internet and none of them works.

    • WPBeginner Support says

      If you want to use the custom code on a custom post type and the method we have is not working, you could try changing is_single() to: is_singular( $post_types = ” )
      and place the name of your custom post type in the single quotes

      管理者

  17. Minh Hieu says

    Can you help me?

    How to insert ads before an ID element?

    Ex: i want to insert ads before

    Thanks you very much!

  18. JOHN HOBBS says

    Thanks for everything you provide. It’s truly appreciated. But question. This article reads

    Last updated on May 2nd, 2014

    at the top. Is the information presented still valid and up-to-date?

    You guys have been a tremendous help to me so I feel bad asking but I need to know.

    Again, thanks for the great resources you provide!

    John

  19. Tell.com.ng says

    Please I need a clearly defined way to add more than one ad after different paragraphs.

    Reply needed urgently please.
    Thanks!

  20. Atul says

    i am using infinite scroll featured theme and post advert plugin for ads but ads show only on first post, not next post. how can i solve it. this plugin does not repeat ads between post.

  21. Melissa says

    This is by far the easiest plugin I’ve ever used! It works perfectly and looks great. Thank you so much! WPBeginner has been a huge help to me in starting my new blog! :)

  22. Hoàng Trí says

    So I Want to insert ads by tag (Like Gym, Fitness) only two tag will show ads, and other will not. How i can do it ?

  23. Bob says

    How can I place an ad before the first paragraph..underneath the single post image? When i set the number to”0″…nothing happens?

  24. Qasim Iqbal says

    Hey, If I added the code using Post advert, would it be on every post? right?
    If not then tell me, I want that

  25. Bright Joe says

    Thank you so much for the code for the functions.php. This just lets me avoid so many unnecessary plugins.

    Thanks again!

  26. David says

    Was sincerely helpful to start off for my presentation at Kampala WordCamp 2017.
    Really incredible help from you.

  27. Adem says

    for more as one ad, change to this:

    $ad_code = ‘Ads code goes here’;

    $ad_code2 = $ad_code;

    if ( is_single() && ! is_admin() ) {
    $content = prefix_insert_after_paragraph( $ad_code, 2, $content );
    $content = prefix_insert_after_paragraph( $ad_code2, 8, $content );
    return $content;
    }
    return $content;
    }

    Thanks!

  28. Shehab says

    I want to show two ads on my post. How can I do it?
    That process you showed, here I can see only one ad on every post. but I want to show two ads in every post

  29. shuseel says

    I want to implement ads code other than Adsence code using JavaScript code.

    The above code does not work when I have replaced JavaScript code on Ads code goes here.

    Please suggest me how to implement
    on the place of text.

  30. phil says

    Hi,

    Congratulation for this function.php code ! Works well

    I ve a question :

    How can i do for do not display adds on specific posts or pages ?

    Many thx
    Regards
    Phil

  31. Aditya says

    I am using Admiral theme and I want to display ads above the thumbnail of every post. What can I do ?

  32. Shubhamk says

    I installed the plugin, I created my ads in the post but it appears at the bottom, not at the start.

  33. Sally says

    Hi, I installed the plugin on my wp site and followed the instructions – post ad and edit settings to show ads on posts. But the ads don’t show on my posts. Do you know why? thanks in advance!

  34. Gail says

    Have just started using the plug-in and it works great!! A question: I now want to insert a new ad. Do I have to trash the old one and then create a new one? Or can I reserve the old one for a future use? Seems like I do have to trash it to make room for the new one. Thanks.

  35. Percival says

    I am wondering if it’s possible to insert a widget, rather than $ad_code = ‘Ads code goes here’;

    Is this possible? I can’t seem to implement the syntax correctly, as inserting a widget seems not to respect the paragraph numbering, and randomly inserts a “1” into the text:

    $ad_code .= dynamic_sidebar(‘test’);

    • hassan says

      did you mean code for ads?………
      you have to visit your ads network be it google adsense or for your ads code then insert it between insert here……….

    • Stephen says

      You have to make a Google Adsense account and make an ad within that. Then, you take the code they give you for the newly created ad and insert it there.

  36. Jagadish Prasad B says

    I want to put my ads in the middle of the content by using an editor. Pleas e suggest me how to add the code in the editor. Thanks for the support.

    • Ryan S says

      Creating shortcode is the best fit on your end, so first, you need to create Shortcode ads and then use that shortcode in your article/post.

      Ryan S

  37. Vỹ Spirit says

    Hello, After I add the above code to the function.php file, my article does not display ads, instead, and it’s adsbygoogle text …. How do I fix it?

    • hassan says

      i did mine some minutes ago and it work well try to remove the <?php if your functon.php already have it…….

  38. Enrique Grobbelaar says

    This app seems to work for everyone, except me. :-( I have followed all the steps, said it should display after paragraph 3. Now there is a large white block on all posts below paragraph 3, but no ad.

    Does somebody perhaps know what I am doing wrong?

    (Using Google Adsense)

  39. Great says

    Thanks you for the tutorials, I used the post ad on my site is working perfectly well but can not open in a new window. Pls how do I set the post ad banners to open in a new window?

返信を残す

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