Chez WPBeginner, nous écrivons de nombreux tutoriels qui nécessitent d’insérer du code dans les sections <header> ou <footer> de votre site WordPress. Cela peut sembler être une tâche décourageante, d’autant plus que WordPress ne fournit pas d’option intégrée pour ajouter des extraits de code dans l’en-tête et le pied de page.
Mais, l’ajout de code d’en-tête et de pied de page dans WordPress est nécessaire lorsqu’on essaie d’intégrer des services web tels que Google Analytics, Google Search Console, Facebook Pixel, et plus encore.
Vous pouvez également rencontrer des tutoriels WordPress qui vous demandent d’ajouter du CSS personnalisé ou du code JavaScript à votre en-tête ou pied de page WordPress.
Heureusement, il existe une solution simple pour les débutants. Avec l’extension gratuite WPCode, vous pouvez ajouter le code en toute sécurité sans modifier directement les fichiers de votre thème WordPress.
Dans cet article, nous allons vous afficher comment ajouter facilement le code de l’en-tête et du pied de page dans WordPress.
La meilleure façon d’ajouter le code de l’en-tête et du pied de page de WordPress
Si vous souhaitez ajouter le code de l’en-tête et du pied de page de WordPress, trois solutions sont possibles :
- Manuellement, en modifiant les fichiers header.php et footer.php de votre thème.
- Avec la fonctionnalité de code d’en-tête et de pied de page intégrée à votre thème.
- Utilisation d’une extension WordPress
La première option n’est pas adaptée aux débutants car elle requiert que vous ajoutiez le code de l’en-tête et du pied de page en modifiant directement les fichiers header.php et footer.php à la main.
Un autre inconvénient de l’utilisation de cette méthode est que votre code sera retiré si vous installez une mise à jour de votre thème.
La deuxième option consiste à utiliser la fonctionnalité intégrée de votre thème. Certains thèmes WordPress comme Elegant Themes et Genesis Framework de StudioPress offrent une option intégrée pour ajouter rapidement du code et des scripts à votre en-tête et pied de page WordPress.
Si vous utilisez un thème avec une fonctionnalité en avant, alors cela semble être une solution sûre et simple. Cependant, si vous modifiez votre thème, alors tous les extraits de code ajoutés à votre site disparaîtront. Cela inclut la vérification du site dans Google Search Console, l’analyse du site via Google Statistiques, etc.
C’est pourquoi nous recommandons toujours aux utilisateurs/utilisatrices d’utiliser la troisième option, une extension d’en-têtes et de pieds de page. Cette option est de loin la méthode la plus simple et la plus sûre pour ajouter du code d’en-tête et de pied de page dans WordPress.
Suite à de nombreuses demandes de la part des Lecteurs, notre équipe a développé l’extension WPCode.
WPCode (anciennement Insert Headers and Footers) est une extension d’extraits de code 100% gratuite. Vous pouvez l’utiliser pour ajouter facilement du code à l’en-tête et au pied de page dans WordPress.
Voici quelques avantages de l’utilisation de l’extension WPCode :
1. Facile, rapide et organisé: Il vous permet d’ajouter du code à l’en-tête et au pied de page de votre site facilement et rapidement. De plus, il vous permet de stocker tous vos codes d’en-tête et de pied de page en un seul endroit.
2. Prévient les erreurs: La validation intelligente des extraits de code aide à prévenir les erreurs susceptibles de se produire si vous modifiez manuellement les fichiers de votre thème.
3. Passer à la version ou changer de thème sans souci: L’extension enregistrera le code de votre en-tête et de votre pied de page dans un endroit séparé, de sorte que vous pouvez mettre à jour ou modifier votre thème sans vous soucier de l’effacement du code.
Outre les scripts d’en-tête et de pied de page, vous pouvez également utiliser WPCode pour insérer facilement des extraits de code PHP, JavaScript, CSS, HTML et texte personnalisés sans modifier les fichiers de votre thème.
De plus, WPCode dispose d’une bibliothèque d’extraits intégrée où vous pouvez trouver tous les extraits de code WordPress les plus utiles. Cela vous permet de retirer rapidement les fonctionnalités de WordPress dont vous ne voulez pas comme les mises à jour automatiques, l’API REST, XML-RPC, les commentaires, et bien d’autres encore.
Note : Si vous souhaitez bénéficier de fonctionnalités avancées telles qu’une bibliothèque d’extraits dans le cloud privé, des pixels de conversion, des extraits planifiés, des révisions de code, et plus encore, vous pouvez mettre à niveau vers WPCode Pro.
Pour plus de détails, lisez notre guide sur la façon d’ajouter facilement du code personnalisé dans WordPress.
Ceci étant dit, voyons comment ajouter facilement du code d’en-tête et de pied de page dans WordPress à l’aide de l’extension WPCode.
Tutoriel vidéo
Si vous ne souhaitez pas regarder le tutoriel vidéo, vous pouvez continuer à lire la version texte ci-dessous :
Ajout de code dans l’en-tête et le pied de page de WordPress
La première chose à faire est d’installer et d’activer l’extension gratuite WPCode. Pour plus de détails, consultez notre guide étape par étape sur l’installation d’une extension WordPress.
Une fois l’extension activée, allez dans Extraits de code » En-tête et pied de page depuis votre panneau d’administration WordPress. Après cela, vous verrez une boîte » En-tête » où vous pouvez ajouter votre code.
Si vous défilez vers le bas, vous verrez également un « corps » et un « pied de page ».
Il vous suffit de coller le code dans l’une des trois cases. Une fois que vous avez terminé, n’oubliez pas de cliquer sur le bouton « Enregistrer les modifications » pour stocker vos réglages.
L’extension va maintenant charger automatiquement le code dans les Emplacements respectifs de votre site WordPress.
Vous pouvez toujours modifier et retirer tout code que vous ne souhaitez pas conserver.
L’extension doit être installée et activée en permanence. En désactivant l’extension, vous cesserez d’ajouter tout le code personnalisé à votre site.
Si vous désactivez accidentellement l’extension, le code sera toujours stocké en toute sécurité dans votre base de données WordPress. Vous pouvez simplement réinstaller ou réactiver l’extension, et le code recommencera à apparaître.
Note : Il se peut que vous deviez vider votre cache WordPress après avoir enregistré les modifications, afin que le code apparaisse correctement sur l’interface publique de votre site.
Nous avons trouvé que la raison principale pour laquelle beaucoup de débutants utilisent l’extension WPCode est d’ajouter Google Analytics à leur site. Pour cela, nous recommandons d’utiliser l’extension gratuite MonsterInsights.
MonsterInsights est la meilleure extension Google Analytics pour WordPress. Il vous aide à configurer correctement le suivi Google Statistiques en quelques clics, et il vous affiche des statistiques utiles directement dans votre tableau de bord WordPress.
Pour obtenir des instructions étape par étape, consultez ce tutoriel sur l ‘installation de Google Analytics dans WordPress.
Nous espérons que cet article vous a aidé à apprendre comment ajouter facilement du code d’en-tête et de pied de page sur WordPress. Vous pouvez également consulter notre guide sur la façon d’afficher du code sur votre site WordPress ou nos choix d’experts sur les meilleurs outils de développement WordPress.
Si vous avez aimé cet article, veuillez alors vous abonner à notre chaîne YouTube pour obtenir des tutoriels vidéo sur WordPress. Vous pouvez également nous trouver sur Twitter et Facebook.
Shahad
my header and footer in not showing in particular page..how can i solve it
WPBeginner Support
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.
Administrateur
Lio
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?
WPBeginner Support
Not at the moment, for the time being, the plugin adds the code to all pages by default
Administrateur
Keith
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!
WPBeginner Support
For the font size, you would want to take a look at our article here: https://www.wpbeginner.com/beginners-guide/how-to-change-the-font-size-in-wordpress/
Administrateur
katrina
I used your insert headers and footers plugin and it was soooo easy and helpful! Thank you so much!
WPBeginner Support
You’re welcome, glad our plugin was helpful
Administrateur
Deeksha
Hello,
Can I add google adsense code to my free blog »s header?
WPBeginner Support
If you mean a WordPress.com site then they currently don’t allow Adsense on their free plan.
Administrateur
Jeremy
I’m trying to connect my website to adsense in order to set up an account.
So far google did not see the code.
WPBeginner Support
You may want to ensure you’ve cleared any caching on your site as one of the most common reason
Administrateur
PJ
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.
WPBeginner Support
That would be because you are on WordPress.com, our tutorials are for WordPress.org sites. You can see the difference between the two here: https://www.wpbeginner.com/beginners-guide/self-hosted-wordpress-org-vs-free-wordpress-com-infograph/
Administrateur
Dipak
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.
WPBeginner Support
You could certainly add as many codes as you need in the header section depending on your needs.
Administrateur
Michael
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.
WPBeginner Support
At the moment the plugin does not allow PHP code to be added.
Administrateur
Michael
Thank you for your reply. Will, that ability be added in the future?
WPBeginner Support
Currently, it is not planned but we will certainly look into it as a possibility if the need increases
moschino
pls can i use both facebook tracking pixel and google analytics on a single wp page?
WPBeginner Support
Yes, you can.
Administrateur
Ray Sagacious Ashia
Can You add more than one header code, to the plug-in, for example
AdSense code and YouTube Verification code.
WPBeginner Support
Yes, you can
Administrateur
Adewale Mudasiru
Hi, I’m trying to add a javascript to my site header but on click on save it says page not found
WPBeginner Support
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.
Administrateur
Poonam Kandpal
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?
WPBeginner Support
If the plugin is installed you should be able to add the code under Settings>Insert Headers and Footers
Administrateur
Faris Naqib
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
WPBeginner Support
In case you need to edit the code later, it is normally best to add the new code on the next line
Administrateur
rodrigo
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)
WPBeginner Support
You may want to try the method in our article here: https://www.wpbeginner.com/beginners-guide/how-to-manually-update-wordpress-plugins-via-ftp/
Administrateur
Arp
What role is needed to access this plugin – is it for admins only or can it be provided to editors too?
WPBeginner Support
The plugin is set up to only allow admins access at the moment.
Administrateur
Marcus
Hi,
After I insert the Header code, when I click « save », will auto link to Page 404 error. How can I fix it?
WPBeginner Support
You would want to start with some of our recommended solutions in our article here: https://www.wpbeginner.com/wp-tutorials/how-to-fix-wordpress-posts-returning-404-error/
Administrateur
Judy
Can I add multiple/different codes in the headers sections? ie. one from google analytics and one from blogmote
WPBeginner Support
As long as you paste the code so it is separate code then you certainly can.
Administrateur
Jon
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?
WPBeginner Support
Normally you shouldn’t but if you run into any conflicts you can reach out to the plugins supports
Administrateur
Jon
Thank you.
WPBeginner Support
You’re welcome
maddy
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!
WPBeginner Support
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.
Administrateur
SirPhren
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?
WPBeginner Support
That is quite odd, you may want to see if an error happened with your htaccess file when you saved: https://www.wpbeginner.com/wp-tutorials/how-to-fix-wordpress-posts-returning-404-error/
as the most common reason for 404 errors, if not you could use our troubleshooting article here: https://www.wpbeginner.com/beginners-guide/beginners-guide-to-troubleshooting-wordpress-errors-step-by-step/
Administrateur
Kanyi Daily
Should i deactivate and delete the plugin after inserting the code?
Will the code be deleted as soon as the plugin is deactivated?
WPBeginner Support
You would want to leave the plugin active, if you deactivate the plugin the code you’ve added will no longer be included.
Administrateur
Kirsty Bennetts
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.
WPBeginner Support
At the moment the plugin should work with the most recent version of WordPress but if you are concerned with the not tested number then you may want to take a look at our article: https://www.wpbeginner.com/opinion/should-you-install-plugins-not-tested-with-your-wordpress-version/
Administrateur
Eya
Thank you.
WPBeginner Support
Glad our article was helpful
Administrateur
ken doughty
Hiya,
Thanks for recommending the Header and Footer plugin, and I have added code to just a single post only to prevent any issues.
I’ve noticed though, that my dropdown menu has stopped showing (just on the page with code). Do you have a Javascript fix, please?
http://www.phhsolicitors.co.uk/calc/
Hope you can help.
Merry Xmas!!!!
WPBeginner Support
Hey Ken,
Try uninstalling the plugin to see if that fixes your issue.
Administrateur
Heather
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.
Kendra
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
WPBeginner Support
You would add the new code on the next line as if you copied the entire code for each they should close themselves.
Administrateur
Yovann
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
mohamed ballouti
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.
WPBeginner Support
Hi Mohamed,
Yes you can add code from multiple sites like Analytics, Webmaster tools, and so on.
Administrateur
Samantha
Like they asked, what is the difference between placing the code in the header or footer?
Thanks!
WPBeginner Support
The code would be run sooner when placed in your header which makes it less likely to prevent loading due to a bad script when placed in the header
Gerardo
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
Knut
Hi
How do I use that bolean filter if I want to disable the header on page 65?
Brgds.
Knut
WPBeginner Support
Hi Knut,
Here is the sample code that you can use to exclude header from any page using the page ID.
1-click Use in WordPress
Administrateur
Marvin
Code added under your footer or header code in the plugin?
WPBeginner Support
Hi Marvin,
No, this code will be added in your theme’s functions.php file.
Tom S.
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?
Faith
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.
Claire Plaisted
I wish this was available for Premium Accounts as well as Business. Is there another way to embed code in your site
WPBeginner Support
Hi Claire,
You are probably using WordPress.com. Please see our guide on the difference between self hosted WordPress.org vs free WordPress.com blog.
Administrateur
Iboro William
This has been quite helpful!
Mo
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.
Alex
Hello, is there a way to insert header code only to certain posts or to posts in a certain category?
Randy Trelka
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.
WPBeginner Support
Hi Randy,
Please see our guide on how to fix 403 forbidden error in WordPress.
Administrateur
Prolete Atienza
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
Riddhi
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 ?
WPBeginner Support
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.
Administrateur
Debbie
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.
Ralph Machin
Any idea when this plugin will be updated for WP 4.9.1? Looks like it’s only compatible up to 4.8.4
WPBeginner Support
Hi Ralph,
You can safely install the plugin. For more on this topic please see our article should you install plugins not tested for your WordPress version.
Administrateur
Jesse
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
Gareth Parmar
So, can I disable this notification after install anywhere?
I don’t need all my multisite clients to see this notification!!
Brandon
When I add my code into the header or footer section in the plugin, does it apply it across all my pages? Thanks.
WPBeginner Support
Hi Brandon,
Yes, it would apply to all pages on your website.
Administrateur
Rolland
HI
How do i add the code to a single page header (not a post) so it appears only on that page?
WPBeginner Support
Hey Rolland,
This plugin will add header and footer code to all pages and posts. If you want to add it to just a single page, then you will have to manually add your code to your theme and surround it with a conditional php tag. For example:
1-click Use in WordPress
Don’t forget to replace 22 with your actual page ID.
melody
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?
Prava
im a new leaner and im facing problem in converting footer content in to dynamic wordpress content
Wendy K
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.
Geraldinesmythe
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
WPBeginner Support
Hello,
Please take a look at Adsanity plugin.
Administrateur
Gareth
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.
Gareth
Does that mean that I can’t disable the notice? (without hacking the plugin)