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.
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.
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.
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.
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”.
È 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.
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.
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.
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.
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”.
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.
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.
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”.
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.
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.
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.
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”.
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.
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!
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
Erika says
Will the Ad Sanity allow to place external ads on an individual post only not on the entire site?
WPBeginner Support says
If you wanted to you can only display ads on one post!
Admin
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
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
Marvin says
How can i make it to repeat (For Example. to repeat after paragraph 2.)?
WPBeginner Support says
We do not have a recommended method for having the code repeat at the moment.
Admin
Deepak says
Fascinating. It is so easy. Thank you guys.
WPBeginner Support says
You’re welcome
Admin
Mi Monir says
This is working. Thanks a lot.
WPBeginner Support says
You’re welcome
Admin
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
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
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.
Admin
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.
WPBeginner Support says
Glad we could give you a starting point
Admin
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
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?
WPBeginner Support says
Sadly, not at the moment.
Admin
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
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?
WPBeginner Support says
For adding Adsense you would want to take a look at our article here: https://www.wpbeginner.com/beginners-guide/how-to-add-google-adsense-to-your-wordpress-site/
Admin
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
Sangam says
How to repeat? After 3rd/6th/9th/12nd etc?
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
Ahsan Ali says
How to insert ad after each & every 3rd paragraph in a single post?
Kindly guide!
WPBeginner Support says
You would need to use the site-specific plugin method and change the 2 to a 3 on line 12
Admin
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
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
Swagatam Innovations says
It worked like charm, thanks very much for this code!
WPBeginner Support says
Glad our article could help
Admin
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!
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
WPBeginner Support says
Hi John,
The plugin mentioned in the article is still available and works great.
Admin
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!
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.
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!
rishabh shrivastava says
It was helpful! Thanks
sandeep says
thank you so much its working dude
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 ?
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?
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
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!
Martijn says
Hi,
Thanks for the code!
How can I exclude certain posts?
Greetings,
Martijn
David says
Was sincerely helpful to start off for my presentation at Kampala WordCamp 2017.
Really incredible help from you.
Segun says
how can i insert HTML code in my ad space?
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!
Bright Joe says
Thank you so much!
Akios says
Don’t know how to insert it
Sunil Kumar says
Thanks! It worked.
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
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.
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
Andrea says
Nice code! How insert only for a certain author post?
Aditya says
I am using Admiral theme and I want to display ads above the thumbnail of every post. What can I do ?
Shubhamk says
I installed the plugin, I created my ads in the post but it appears at the bottom, not at the start.
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!
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.
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’);
John says
Percival, did you figure out a solution? Trying to do something similar.
Morgan says
Where do I get a code for an ad .?
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.
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
hsabarp says
thanks
this is the what i was searching for…….
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…….
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)
Enrique Grobbelaar says
Never mind. It is working now.
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?