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

Come aggiungere il codice dell’intestazione e del piè di pagina in WordPress (in modo semplice)

Noi di WPBeginner scriviamo molti tutorial che richiedono l’inserimento di codice nelle sezioni <header> o <footer> del vostro sito web WordPress. Questo può sembrare un compito scoraggiante, soprattutto perché WordPress non fornisce un’opzione integrata per aggiungere snippet di codice nell’header e nel footer.

Tuttavia, l’aggiunta di codice header e footer in WordPress è necessaria quando si cerca di integrarsi con servizi web come Google Analytics, Google Search Console, Facebook Pixel e altri ancora.

Potreste anche imbattervi in tutorial di WordPress che vi chiedono di aggiungere del codice CSS personalizzato o JavaScript all’header o al footer di WordPress.

Fortunatamente, esiste una soluzione semplice per i principianti. Con il plugin gratuito WPCode, è possibile aggiungere in modo sicuro il codice senza modificare direttamente i file del tema di WordPress.

In questo articolo vi mostreremo come aggiungere facilmente codice header e footer in WordPress.

How to Add Header and Footer Code in WordPress

Il modo migliore per aggiungere il codice dell’intestazione e del piè di pagina di WordPress

Se volete aggiungere il codice dell’intestazione e del piè di pagina di WordPress, ci sono tre possibili soluzioni:

  1. Manualmente, modificando i file header.php e footer.php del proprio tema
  2. Con la funzione di codice dell’intestazione e del piè di pagina incorporata nel vostro tema
  3. Utilizzo di un plugin di WordPress

La prima opzione non è adatta ai principianti, perché richiede di aggiungere il codice dell’intestazione e del piè di pagina modificando direttamente i file header.php e footer.php manualmente.

Un altro svantaggio di questo metodo è che il codice verrà rimosso se si installa un aggiornamento del tema.

La seconda opzione consiste nell’utilizzare la funzione integrata del vostro tema. Alcuni temi WordPress come Elegant Themes e Genesis Framework di StudioPress offrono un’opzione integrata per aggiungere rapidamente codice e script all’intestazione e al piè di pagina di WordPress.

Se si utilizza un tema con una funzione integrata, sembra una soluzione semplice e sicura. Tuttavia, se cambiate il tema, tutti gli snippet di codice aggiunti al vostro sito web spariranno. Questo include la verifica del sito in Google Search Console, l’analisi del sito tramite Google Analytics e così via.

Per questo motivo consigliamo sempre agli utenti di utilizzare la terza opzione, un plugin per header e footer. Questa opzione è di gran lunga il metodo più semplice e sicuro per aggiungere codice header e footer in WordPress.

Dopo molte richieste da parte dei lettori, il nostro team ha creato il plugin WPCode.

WPCode

WPCode (ex Insert Headers and Footers) è un plugin per snippet di codice gratuito al 100%. È possibile utilizzarlo per aggiungere facilmente codice all’intestazione e al piè di pagina di WordPress.

Ecco alcuni vantaggi dell’utilizzo del plugin WPCode:

1. Facile, veloce e organizzato: Consente di aggiungere codice all’header e al footer del sito in modo facile e veloce. Inoltre, consente di organizzare i codici del footer e dell’header in un unico posto.

2. Previene gli errori: La convalida intelligente dei frammenti di codice aiuta a prevenire gli errori che possono verificarsi se si modificano manualmente i file del tema.

3. Aggiornamento o modifica del tema senza preoccupazioni: il plugin salva il codice dell’intestazione e del piè di pagina in un luogo separato, in modo da poter aggiornare o modificare il tema senza preoccuparsi che il codice venga cancellato.

Oltre agli script per l’intestazione e il piè di pagina, è possibile utilizzare WPCode per inserire facilmente frammenti di codice PHP, JavaScript, CSS, HTML e testo personalizzati senza modificare i file del tema.

Inoltre, WPCode dispone di una libreria di snippet integrata in cui è possibile trovare tutti gli snippet di codice WordPress più utili. Questo vi permette di rimuovere rapidamente le caratteristiche di WordPress che non desiderate, come gli aggiornamenti automatici, REST API, XML-RPC, commenti e altro ancora.

Nota: se si desiderano funzioni avanzate come una libreria di snippet in cloud privata, pixel di conversione, snippet programmati, revisioni del codice e altro ancora, è possibile passare a WPCode Pro.

Per maggiori dettagli, leggete la nostra guida su come aggiungere facilmente codice personalizzato in WordPress.

Detto questo, vediamo come aggiungere facilmente il codice dell’intestazione e del piè di pagina in WordPress utilizzando il plugin WPCode.

Aggiunta di codice all’intestazione e al piè di pagina di WordPress

La prima cosa da fare è installare e attivare il plugin gratuito WPCode. Per maggiori dettagli, consultate la nostra guida passo-passo su come installare un plugin di WordPress.

Una volta attivato il plugin, andate su Code Snippets ” Header & Footer dal pannello di amministrazione di WordPress. Successivamente, verrà visualizzato un riquadro “Intestazione” in cui è possibile aggiungere il codice.

Add code to header and footer with WPCode

Se si scorre verso il basso, si vedranno anche un riquadro “Corpo” e un riquadro “Piè di pagina”.

Header and footer script boxes WPCode

È sufficiente incollare il codice in una delle tre caselle. Una volta terminato, non dimenticate di fare clic sul pulsante “Salva modifiche” per memorizzare le impostazioni.

Il plugin caricherà automaticamente il codice nelle rispettive posizioni del sito WordPress.

È sempre possibile modificare e rimuovere il codice che non si desidera mantenere.

È necessario mantenere il plugin sempre installato e attivato. La disattivazione del plugin interromperà l’aggiunta di tutto il codice personalizzato al sito.

Se si disattiva accidentalmente il plugin, il codice sarà ancora memorizzato in modo sicuro nel database di WordPress. È sufficiente reinstallare o riattivare il plugin e il codice ricomincerà a comparire.

Nota: potrebbe essere necessario cancellare la cache di WordPress dopo aver salvato le modifiche, in modo che il codice venga visualizzato correttamente sul front-end del sito web.

Abbiamo riscontrato che il motivo principale per cui molti principianti utilizzano il plugin WPCode è l’aggiunta di Google Analytics al loro sito web. Per questo, consigliamo di utilizzare il plugin gratuito MonsterInsights.

MonsterInsights è il miglior plugin di Google Analytics per WordPress. Consente di impostare correttamente il monitoraggio di Google Analytics facendo pochi clic e mostra statistiche utili direttamente nella dashboard di WordPress.

Per le istruzioni passo-passo, vedere questo tutorial su come installare Google Analytics in WordPress.

Video tutorial

Se non vi piace seguire le istruzioni scritte, potete guardare il nostro video tutorial su come add-on il codice header e footer in WordPress:

Subscribe to WPBeginner

Speriamo che questo articolo vi abbia aiutato a capire come aggiungere facilmente codice header e footer in WordPress. Potreste anche consultare la nostra guida su come visualizzare il codice sul vostro sito WordPress o la nostra selezione dei migliori strumenti di sviluppo per WordPress.

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

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

266 commentiLeave a Reply

    • You would want to check with your specific theme’s support for the header not appearing on a specific page as it could be a page specific template causing you issues.

      Admin

  1. Thanks guys for your plugin! I used it to add FB Pixel to my site, but now I have a landing page and I need a different Pixel event (Lead) on the Thank You page after visitors confirm their details. Can I use the plugin to add the script to a specific page?

  2. Hi, is there a way to change the font size of the footer?
    I tried keying in a chunk of disclaimer text but it is too large.

    Thanks in advance!

    • You may want to ensure you’ve cleared any caching on your site as one of the most common reason

      Admin

  3. You need to change your messaging/advertising regarding header/footer plug-in being free to install. It is not free unless you have purchased the Business plan for your page.

  4. How many codes we can add in single header or footer section, I mean can i use two or three codes in single header section like facebook code google code etc.

  5. Was wondering if PHP can be added in the header section. Like adding Yoast’s Breadcrumb code to the header so I don’t have to go into my theme files.

  6. Can You add more than one header code, to the plug-in, for example
    AdSense code and YouTube Verification code.

    • You may want to try resaving your permalinks and checking with your hosting provider that they are not receiving an error on your site that would be preventing the page from saving.

      Admin

  7. Thank you so much for your video, although I have copied the code still I’m not able to enable my header. How to do it?

    • If the plugin is installed you should be able to add the code under Settings>Insert Headers and Footers

      Admin

  8. Hi. I already install the plugin and it’s work. But how to add more than 1 code? Just copy like that or I need to make 1 space to copy the code

  9. Cant update “Insert Headers and Footers Plugin”.
    Error message: Update Error: Not possible to eliminate previous version of plugin. (translation from spanish)

    When trying to remove the plugin: ” insert-headers-and-footers-old/ihaf.php could not be removed completely .” (translation from spanish)

  10. I have another plugin it seems to work almost exactly the same way only it can be used on a single page or customized as to which pages the script is added.

    I am trying the WpBeginner plugin just because I trust y’all.

    Am I likely to run into problems having both added to my site?

    Using yours for the whole site, and the other one for adding something only to the header or footer of an individual page?

  11. Hello,
    I’m trying to update something in my footer section.
    I have already downloaded and installed/ used this plug in previously and it is working currently. However, when I try to go edit it, when my cursor is hovering over settings…. no drop out menu appears to go to –>insert header and footer. It only takes me to my account setting page. Please help me because I need to update my mailing list options asap! Thank you!

    • If you go to your settings area, it should expand the other options for you to be able to see the Insert Headers and Footers menu item.

      Admin

  12. Thanks WPbeginer,

    I tried saving the plugin when I added my google search console code, it redirected me to error 404.

    What could be wrong?

  13. Should i deactivate and delete the plugin after inserting the code?

    Will the code be deleted as soon as the plugin is deactivated?

    • You would want to leave the plugin active, if you deactivate the plugin the code you’ve added will no longer be included.

      Admin

  14. Hello. I’ve been using this plugin for some time and find it invaluable.
    However, I am about to update to WordPress 5 but on the download page, it says ‘Compatible up to 4.9.9’. This makes me wary – will it work with 5 and are there plans to update it? Thank you.

  15. I have added this to my site. It reads it just fine, but prints the code across the top of my header bar EVERY time! Not sure how to fix this.

  16. Plsss explian in details how to add more than one code in the headers space, cos i have already inserted ,google search console code with the pluggin how am i going to add the adsene code in the same headers section

    • You would add the new code on the next line as if you copied the entire code for each they should close themselves.

      Admin

  17. How do I add a HTLM code in the header of my theme. I dont quite understand where it is. I use Xtheme and some people said to go to appearance and editor, but I dont have no editor.

    I need to add the Gtag in the heard of my website for Google analytics and I dont want to use a plug in

  18. I want to ask you about this plugin.
    Can I put more than one code from different sites (eg Google Analytics code, Webmaster’s code, and Adsense ad code) Will the number of codes affects their performance because I see a difference in terms of visitors Google Analytics and WordPress analytics(WP Statistics)?
    And the difference between placing the code in the header and in the footer?
    Thank you sorry for bothering you
    I hope you will respond quickly.

  19. Hi, is it possible use this plugin to add more scripts? For example i need to add the AdSense and PushCrew codes.

    If possible, just copy the code one under the other?

    Thanks

  20. So far so good. I’ve been trying to search your site for code to insert line breaks and center text. Any urls to these explanations?

  21. Thank you so so much. That solved my problem. I would also love to know if there’s a way to solve the error code I get in my theme codes. I’ve got 53 error when I view the source code.

  22. I wish this was available for Premium Accounts as well as Business. Is there another way to embed code in your site

  23. I’ve installed header and footer plugin, entered the relevant code and saved it. When I look in header script in header editor I can’t see the relevant code I’ve just entered. Please advise.
    Thank you.

  24. When I try to add header code using the plug in I get a 403 forbidden page. How do I get around this? I temporarily tried to turn off my security but that didn’t help.

  25. Hi, Iam looking for option like this but for a multi-site,

    but I need is like a general admin for network-wide option,
    where when i config this, it will show to the header on all sub-site,

    currently, I need to set this for every sub-site plugin config.

    is there any way to have the plugin option of this menu under network option or something and not per sub-site.

    is there any other option i can use/do.

    thanks

  26. Hey, is there anyway to check if the code has been inserted ? Can’t detect it in my site source code nor in the headers.php file. Is is possible for this plugin to not be working ?

    • Hi Riddhi,

      Once you add the code and save your changes you will be able to see the code in your site’s source code. For header code you will find it between <head> and </head> tags. Footer code will be added before the </body> tag.

      Admin

  27. Is there a way to use this to add an image in the header that does not replace the existing header? In other words, I already have a logo there on the left, and a search bar with social media links on the right. The center is empty. I want to add an image widget which links to the source page of the image. I have the widget code ready to insert, but there is no HTML showing in the header.php file. I do not know PHP (i do know HTML quite well).
    I added the widget to the footer, which was easy because in my theme there IS HTML (an HTML table) in the footer. But it is supposed to be at the top of the pages.

  28. Thank you so much for information. I have been so much problem with pasting html adsense code in header. This information helps me a lot

  29. So, can I disable this notification after install anywhere?
    I don’t need all my multisite clients to see this notification!!

  30. When I add my code into the header or footer section in the plugin, does it apply it across all my pages? Thanks.

  31. hi, I just re-added my footer widget embedded code, it’s from keyreply.
    I don’t know what’s went wrong, I could see my footer widget from my pc(while I am logged in WP), however any other devices(pc or mobile phone), the widget is not showing. any ideas?

  32. I installed the insert headers and footers plugin on my clients WordPress site but when I click on it under settings it just shows a blank page. There are no fields available for me to insert text into.

  33. Hi,
    I’m trying to install an html5 banner ad at the top of my home page and a few other page tops. I have a customer that wants to only deliver their banner ad in that format so that as a rotating banner each image links to a different url we’re promoting. Where do I put this code to make it show up? I’ve tried downloading some plugins to place it but nothing is working. We normally just accept jpgs and links but I don’t want to lose this sale as she won’t deliver other than in html5. Thanks for your help! Geraldine

  34. Hi, I love the simplicity of this plugin. There is one annoying point however.

    How can I disable the dashboard notice “Thank you for installing….” in a multisite set up.

    I don’t need all my client sites seeing that notice.

    A solution that doesn’t involve another plugin would be appreciated, preferably I can just remove an action or something.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.