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

Come inserire annunci nel contenuto dei post in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete inserire annunci all’interno del contenuto dei vostri post in WordPress?

Il contenuto dei post è il luogo in cui i visitatori sono più coinvolti nel vostro sito web, il che lo rende il posto perfetto per mostrare un annuncio.

In questo articolo mostreremo tre modi per inserire annunci all’interno del contenuto dei post in WordPress.

How to insert ads within your post content in WordPress

Perché inserire annunci nel contenuto dei post in WordPress?

I banner e le sidebar pubblicitarie sono un ottimo modo per guadagnare con il blogging online con WordPress. Tuttavia, è anche facile che i visitatori li ignorino.

Le persone visitano il sito per leggere i contenuti e potrebbero non prestare attenzione alla barra laterale o ad altre aree della pagina. Poiché i contenuti dei post ricevono la massima attenzione da parte dei visitatori, è il luogo ideale per mostrare gli annunci.

Detto questo, vediamo tre modi diversi per inserire annunci all’interno dei contenuti dei post in WordPress.

Se preferite passare direttamente a un metodo particolare, potete utilizzare i link sottostanti.

Metodo 1. Inserire gli annunci nel contenuto del post usando WPCode (automaticamente)

Un modo per inserire annunci all’interno del contenuto dei post è utilizzare il plugin gratuito WPCode.

WPCode è uno dei migliori plugin per gli snippet di codice di WordPress sul mercato ed è anche uno dei migliori plugin per la gestione degli annunci su WordPress. Permette di inserire facilmente il codice per inserire annunci in qualsiasi pagina, post o area widget del vostro sito WordPress.

È possibile mostrare annunci di reti pubblicitarie di terze parti, come Google AdSense. Oppure, potete mostrare i vostri annunci ospitati, il che è perfetto per vendere annunci sul vostro blog WordPress.

Per iniziare, è necessario installare e attivare il plugin WPCode. Se avete bisogno di aiuto, consultate la nostra guida su come installare un plugin di WordPress.

Dopo l’attivazione, andare su Code Snippets ” + Add Snippet dalla dashboard di WordPress.

Si accede così alla libreria di snippet di codice incorporati. Passare il mouse sull’opzione “Aggiungi codice personalizzato (nuovo snippet)” e fare clic sul pulsante “Usa snippet” per selezionarlo.

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

Successivamente, dovrete dare un titolo al vostro annuncio digitando nel campo “Aggiungi titolo per lo snippet”.

I visitatori del sito non vedranno il titolo, perché è solo un riferimento per voi.

Add title for your ad code snippet in WPCode

Successivamente, è necessario scegliere il tipo di annuncio che si desidera inserire sul proprio sito.

Una possibilità è quella di utilizzare il codice annuncio fornito da un programma come Google AdSense.

Se utilizzate il codice di Google AdSense, vi consigliamo di consultare la nostra guida sulle dimensioni e i formati dei banner Google AdSense più performanti. Abbiamo anche una guida completa su come ottimizzare le entrate di AdSense in WordPress.

Un’altra opzione è quella di creare il proprio annuncio. In questo caso, dovrete ottenere il codice dalla persona che vi paga per mostrare l’annuncio sul vostro sito WordPress o scrivere voi stessi il codice.

Una volta ottenuto il codice dell’annuncio, è sufficiente copiarlo e incollarlo nella casella “Anteprima codice”.

È inoltre necessario selezionare “Snippet HTML” come “Tipo di codice” dall’elenco a discesa sul lato destro dello schermo.

Copy and paste ad code into Code Preview box

Successivamente, scorrere fino alla sezione “Inserimento”. È possibile scegliere tra due opzioni principali di inserimento:

  • Auto-Insert – Il codice dell’annuncio verrà inserito ed eseguito automaticamente sul vostro sito web nella posizione da voi scelta.
  • Shortcode – Il codice dell’annuncio non viene inserito automaticamente. Riceverete uno shortcode che potrete inserire manualmente in qualsiasi punto del vostro blog WordPress.

Fare clic sul metodo “Inserisci automaticamente” per visualizzare automaticamente gli annunci all’interno del contenuto del post.

Quindi, scegliere l’opzione “Inserisci dopo il paragrafo” dall’elenco a discesa accanto al campo “Posizione”.

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

È inoltre possibile modificare il “Numero di inserimento” per scegliere il numero di paragrafi dopo i quali inserire lo snippet. Ad esempio, se si desidera visualizzare l’annuncio dopo il secondo paragrafo anziché il primo, basta sostituire l’1 con il 2.

Oltre a inserire gli annunci dopo un paragrafo, è possibile visualizzare automaticamente gli annunci in posizioni (funzioni di WordPress) come prima o dopo il contenuto, tra i post, prima o dopo gli estratti e altro ancora.

Additional auto-insert locations in WPCode

Con la versione premium di WPCode, è possibile inserire annunci anche in posizioni di WooCommerce come prima o dopo i prodotti, il carrello e la pagina di checkout, solo per citarne alcune.

WPCode Pro consente anche di programmare gli snippet di codice degli annunci con una data di inizio e di fine. Questo è perfetto per visualizzare gli annunci durante le festività natalizie o per altre promozioni a tempo limitato.

Successivamente, è possibile scorrere verso il basso fino alla sezione “Tipo di dispositivo”. Qui si può scegliere se visualizzare l’annuncio su qualsiasi tipo di dispositivo, solo desktop o solo mobile.

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

Se si desidera limitare le pagine o i post in cui lo snippet di codice dell’annuncio viene inserito automaticamente, è possibile scorrere verso il basso fino alla sezione “Logica condizionale intelligente”.

Ad esempio, è possibile nascondere gli annunci su tipi di pagine o URL specifici.

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

Per organizzare i vostri annunci, potete accedere alla sezione “Informazioni di base”. In quest’area è possibile aggiungere tag e note per ricordare a cosa serve lo snippet di codice dell’annuncio.

Add tags to organize your ad code

Esiste anche un campo “Priorità” che consente di controllare l’ordine di esecuzione degli snippet quando si desidera visualizzare più snippet nella stessa posizione.

Tutti gli snippet hanno una priorità predefinita di 10. Se si desidera che il codice dell’annuncio venga visualizzato prima degli altri, è sufficiente impostare la priorità su un numero inferiore.

Una volta terminato il lavoro sul vostro annuncio, è il momento di pubblicarlo.

Per farlo, tornare alla parte superiore della pagina e spostare l’interruttore da “Inattivo” ad “Attivo”. Quindi, fare clic sul pulsante “Salva frammento”.

Activate and save ad code in WPCode plugin

Ecco fatto! L’annuncio verrà ora inserito automaticamente nel contenuto del post, se avete selezionato il metodo “Inserimento automatico” illustrato in questo tutorial.

Se invece si sceglie il metodo di inserimento ‘Shortcode’, è possibile creare una nuova pagina o un nuovo post, oppure aprirne uno da modificare. Quindi, basta trovare il punto esatto in cui si desidera mostrare l’annuncio all’interno del contenuto del post e creare un nuovo blocco shortcode.

Si può quindi procedere a incollare lo shortcode in questo blocco. Per istruzioni dettagliate, consultare la nostra guida per principianti su come aggiungere uno shortcode in WordPress.

Ora è possibile visitare la pagina o il post per vedere l’annuncio all’interno del contenuto del post.

Nota: se si visualizzano annunci di Google AdSense, potrebbero essere necessari 20-30 minuti perché l’annuncio venga visualizzato sulla pagina.

Metodo 2. Inserimento di annunci nel contenuto del post con Ad Inserter

Un’altra opzione è quella di utilizzare Ad Inserter. Si tratta di un plugin per la gestione degli annunci su WordPress che può mostrare sia gli annunci ospitati che quelli forniti da una rete.

Se si utilizza una rete, è sufficiente incollare il codice dell’annuncio nel plugin Ad Inserter. Tuttavia, se state creando un annuncio ospitato, dovrete scrivere voi stessi il codice o ottenerlo dalla persona che paga per mostrare il suo annuncio sul vostro sito.

La prima cosa da fare è installare e attivare il plugin gratuito Ad Inserter. Se avete bisogno di aiuto, consultate la nostra guida su come installare un plugin di WordPress.

Dopo l’attivazione, andare su Impostazioni ” Inseritore di annunci.

The Ad Inserter WordPress plugin

In questa schermata, ogni scheda rappresenta un annuncio diverso. In questo modo è possibile creare più annunci diversi e inserirli nel proprio sito web.

A questo punto è possibile digitare o copiare/incollare il codice dell’annuncio che si desidera mostrare all’interno del contenuto del post.

Insert ads within your post content in WordPress using Ad Inserter

Il passo successivo è l’inserimento dell’annuncio nel vostro sito web. Un’opzione è quella di aggiungere l’annuncio a qualsiasi pagina, post o area pronta per i widget utilizzando uno shortcode.

Un’altra opzione è quella di dire ad Ad Inserter di aggiungere automaticamente questo annuncio a ogni post, in una determinata posizione, ad esempio dopo ogni terzo paragrafo.

Se volete aggiungere automaticamente questa pubblicità ai vostri post, iniziate a selezionare la casella “Post”.

The Ad Inserter advert management plugin

Successivamente, è necessario aprire il menu a tendina “Inserimento” e scegliere dove Ad Inserter deve mostrare l’annuncio.

Poiché vogliamo inserire gli annunci all’interno del contenuto del post, di solito si sceglie Prima del paragrafo, Dopo il paragrafo, Prima dell’immagine o Dopo l’immagine.

Placing the ad within your WordPress post content

Dopo aver scelto un’opzione dall’elenco, digitate esattamente la posizione in cui l’annuncio deve apparire.

Ad esempio, se si vuole mostrare l’annuncio dopo il secondo paragrafo, si deve digitare “2”, come si può vedere nell’immagine seguente.

Inserting ads within your post content in WordPress

Quando si è soddisfatti delle impostazioni, fare clic sul pulsante “Salva impostazioni”.

A questo punto Ad Inserter inserirà l’annuncio all’interno del contenuto del post, nella posizione scelta.

Saving your ad settings

Come abbiamo già detto, potete inserire questo annuncio sul vostro sito utilizzando uno shortcode.

A tal fine, fare clic sul pulsante “Manuale” e selezionare la casella “Shortcode”.

Adding an ad to your post content using shortcode

Una volta fatto ciò, è sufficiente copiare lo shortcode di Ad Inserter. Potete quindi fare clic sul pulsante “Salva impostazioni” per salvare il vostro annuncio.

Fatto ciò, siete pronti a inserire questo shortcode in qualsiasi pagina, post o area predisposta per i widget. Per istruzioni passo passo, potete consultare la nostra guida su come aggiungere uno shortcode in WordPress.

Metodo 3. Inserimento di annunci nel contenuto del post tramite codice (avanzato)

È anche possibile aggiungere una pubblicità al contenuto del post in WordPress utilizzando un codice.

Poiché si modifica il codice del sito, questo non è il metodo più semplice per i principianti. Tuttavia, consente di creare annunci senza dover installare un plugin speciale per la gestione degli annunci.

Per inserire un annuncio tramite codice, aprire il file functions.php del tema, creare un plugin specifico per il sito o utilizzare un plugin di snippets di codice.

Anche in questo caso, consigliamo di utilizzare il plugin gratuito WPCode, che consente di incollare facilmente gli snippet in WordPress, senza modificare il file functions.php del tema.

Inoltre, WPCode è dotato di una convalida intelligente degli snippet di codice per aiutarvi a prevenire gli errori di codice più comuni e proteggervi dalla rottura del vostro sito.

Si può quindi aggiungere il seguente codice:

//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 );
}

Questo codice mostrerà un annuncio dopo il secondo paragrafo del contenuto di un post.

Se si desidera mostrare l’annuncio in un’altra posizione, è sufficiente modificare la seguente sezione:

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

Nel codice di esempio qui sopra, si può notare che stiamo inserendo l’annuncio dopo il terzo paragrafo.

Una volta fatto questo, si può procedere a digitare o incollare il codice dell’annuncio. Si tratta del codice che controlla l’aspetto e il comportamento dell’annuncio.

Aggiungerete questo codice come valore $ad_code, che è il punto in cui si dice “Aggiungi codice qui”.

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

Dopo aver fatto questo, si è pronti a pubblicare l’annuncio. Per farlo, attivate il vostro plugin specifico per il sito, salvate le modifiche apportate al file functions.php del vostro sito oppure attivate e salvate il vostro frammento di codice in WPCode.

Ora, se visitate il vostro sito web, dovreste vedere il vostro annuncio dal vivo.

Speriamo che questo articolo vi abbia aiutato a capire come inserire annunci all’interno del contenuto dei vostri post in WordPress. Potreste anche voler imparare a incrementare il traffico del vostro blog o consultare il nostro elenco dei migliori strumenti e plugin SEO per WordPress che dovreste utilizzare.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

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.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

215 commentiLascia una risposta

  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 :)

      Admin

  3. 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 :)

      Admin

  4. 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.

      Admin

  5. 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

      Admin

  6. 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.

      Admin

    • WPBeginner Support says

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

      Admin

  7. 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.

  8. 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.

      Admin

  9. 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?

  10. 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

      Admin

  11. 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?

  12. 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.

      Admin

        • 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

  13. 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.

      Admin

  14. 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

      Admin

  15. 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!

  16. 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

  17. 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!

  18. 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.

  19. 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! :)

  20. 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 ?

  21. 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?

  22. 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

  23. 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!

  24. David says

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

  25. 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!

  26. 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

  27. 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.

  28. 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

  29. 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!

  30. 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.

  31. 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.

  32. 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

  33. 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…….

  34. 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)

  35. 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?

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.