På WPBeginner skriver vi många handledningar som kräver att du infogar kod i avsnitten <header> eller <footer> på din WordPress-webbplats. Detta kan kännas som en skrämmande uppgift, särskilt eftersom WordPress inte tillhandahåller ett inbyggt alternativ för att lägga till kodsnuttar i sidhuvudet och sidfoten.
Men att lägga till header- och footer-kod i WordPress är nödvändigt när man försöker integrera med webbtjänster som Google Analytics, Google Search Console, Facebook Pixel och mer.
Du kan också stöta på WordPress-handledning som ber dig att lägga till lite anpassad CSS- eller JavaScript-kod till din WordPress-huvud- eller sidfot.
Lyckligtvis finns det en enkel lösning för nybörjare. Med det kostnadsfria WPCode Free Plugin kan du lägga till koden på ett säkert sätt utan att direkt redigera dina WordPress Temafiler.
I den här artikeln visar vi hur du enkelt kan lägga till sidhuvud- och sidfotskod i WordPress.
Det bästa sättet att add to WordPress Header och Footer kod
Om du vill add to WordPress header- och footer-kod finns det tre möjliga lösningar:
- Manuellt, genom att editera ditt temas header.php och footer.php filer
- Med ditt temas built-in header- och footer-kodfunktion
- Använda ett plugin för WordPress
Det första alternativet är inte nybörjarvänligt eftersom det kräver att du lägger till header- och footer-kod genom att direkt redigera header.php- och footer.php-filerna manuellt.
En annan nackdel med att använda den här metoden är att din kod kommer att tas bort om du installerar en update till ditt theme.
Det andra alternativet är att använda ditt temas utvalda funktion. Vissa WordPress teman gillar Elegant Themes och Genesis Framework av StudioPress erbjuder ett built-in alternativ för att snabbt lägga till kod och skript till din WordPress header och footer.
Om du använder ett theme med en utvald funktion så gillar du en säker och enkel lösning. Men om du ändrar ditt theme kommer alla code snippets som lagts till på din website att försvinna. Detta inkluderar verifiering av site i Google Search Console, webbplatsanalys via Google Analytics och så vidare.
Det är därför vi alltid rekommenderar användare att använda det tredje alternativet, ett plugin för headers och footers. Detta alternativ är den överlägset enklaste och säkraste metoden att add to header och footer kod i WordPress.
Efter många requests från Läsare, har vårt team byggt WPCode plugin.
WPCode (tidigare Insert Rubriker and Footers) är ett 100% gratis code snippet plugin. Du kan använda det för att enkelt lägga till kod i header och footer i WordPress.
Här är några fördelar med att använda WPCode plugin:
1. Enkelt, snabbt och organiserat: Du kan enkelt och snabbt lägga till kod i sidhuvudet och sidfoten på din webbplats. Dessutom håller det dig organiserad genom att låta dig lagra alla dina sidfot- och sidhuvudkoder på ett ställe.
2. Förhindrar error: Den smarta bekräftelsen av code snippets hjälper till att förhindra error som kan uppstå om du redigerar dina theme-filer manuellt.
3. Upgrade eller ändra ditt tema utan oro: Pluginet kommer att save din header och footer kod på en separat plats, så att du kan uppdatera eller ändra ditt tema utan att oroa dig för att koden raderas.
Notis: Förutom skript för header och footer kan du också använda WPCode för att enkelt infoga customizer PHP, JavaScript, CSS, HTML och text code snippets utan att editera dina temafiler.
Dessutom har WPCode ett built-in snippets-bibliotek där du kan hitta alla de mest användbara WordPress-kod snippets. Detta allow dig att snabbt ta bort WordPress funktioner som du inte vill ha gillar automatiska updates, REST API, XML-RPC, comments, och mer.
Note: Om du vill ha avancerade funktioner som ett privat moln snippet bibliotek, konvertering Pixels, tidsinställda snippets, code revisioner, och mer, kan du uppgradera till WPCode Pro.
För mer details, läs vår guide om hur du enkelt lägger till custom code i WordPress.
Med detta sagt, låt oss se hur du enkelt kan add to header och footer kod i WordPress med hjälp av WPCode plugin.
Video Tutorial
Om du inte vill titta på tutorialen på video, kan du fortsätta att läsa textversionen under:
Lägga till kod i Header och Footer i WordPress
Det första du behöver göra är att installera och aktivera det gratis pluginet WPCode. För mer detaljer, se vår steg-för-steg guide om hur du installerar ett WordPress plugin.
När pluginet är aktiverat, gå till Code Snippets ” Header & Footer från din WordPress adminpanel. Efter det kommer du att se en ”Header” box där du kan add to your kod.
Om du rullar ner ser du också en box för ”Body” och en box för ”Footer”.
Klistra bara in koden i en av de tre boxarna. När du är klar, glöm inte att clicka på knappen ”Save Changes” för att store dina inställningar.
Pluginet kommer nu automatiskt att hämta koden på respektive location på din WordPress site.
You can always edit and remove any code that you don’t want to keep.
Du måste hålla pluginet installerat och aktiverat hela tiden. Deactivate plugin kommer att sluta lägga till all custom code till din site.
Om du av misstag deaktiverar pluginet kommer koden fortfarande att vara säkert lagrad i din WordPress database. You can simply reinstall or reactivate the plugin, and the code will start starting appearance again.
Note: Du kan behöva clear din WordPress-cache efter att du har sparat ändringarna, så att koden visas korrekt on the front end på din website.
Vi har funnit att den största anledningen till att många Beginnare använder WPCode plugin är att add Google Analytics till sin website. För det rekommenderar vi faktiskt att du använder det gratis pluginet MonsterInsights.
MonsterInsights är det bästa Google Analytics-pluginet för WordPress. Det hjälper dig att korrekt ställa in Google Analytics tracking med bara några clicks, och det visar dig användbar statistik direkt i din WordPress dashboard.
För steg-för-steg-instruktioner, se denna tutorial om hur du installerar Google Analytics i WordPress.
Vi hoppas att den här artikeln hjälpte dig att lära dig hur du enkelt kan lägga till sidhuvud- och sidfotskod i WordPress. Du kanske också vill se vår guide om hur du visar kod på din WordPress-webbplats eller våra expertval av de bästa WordPress-utvecklingsverktygen.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
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!
Moinuddin Waheed says
Ever since I have used wpcode on my website, it has reduced many troubles of messing with the functions.php file.
I remember messing with the code back in 2017 and it was horrible.
wpcode makes it easy not only to insert the code snippets but also it helps in easy maintenance.
Moreover, it gives power to avoid lots of plugins to get small functionalities.
Mrteesurez says
Thanks for this guide.
Although adding code to the header and footer was once a big problem for me as I am afraid to loose the custom code when updating my theme, I then created a child theme for this but it was somehow technical.
Now, I am using WPcode to add the code and implement other custom codes with ease, it’s even faster as there are some ready made custom code in WPcode itself. The plugin is very useful, thanks.
WPBeginner Support says
Glad to hear you found the plugin helpful!
Administratör
Jiří Vaněk says
I’ve been using the WpCode plugin for several years and it’s really great. Especially for newbies who are afraid to insert codes into the website. This plugin is almost a must on every website. It can really save a lot of work and here on wpbeginner there are a lot of ready-made solutions.
Pierre-Yves says
Hello
I’ve installed the WPCode plugin and I’ve inserted code in the header field in the ”Global Header and Footer” tab. This code shows a popup.
The website is multisite and WPCode is activated on all the network.
The popup shows well in the home page of my website, but not on other pages where people can land after searching in Google.
What I’ve to do to get the popup showing on any page ?
Thanks
WPBeginner Support says
Just to be certain, does your theme have a style for your other pages that uses a different header or removes the header?
Administratör
Viney Bhatia says
Is there any way to hide the header or footer code for some posts/pages?
WPBeginner Support says
Not at the moment with the plugin.
Administratör
Aamir Nadeem says
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 says
As long as the code is added properly and you’re not placing code within other blocks of code you can add as many as you would like.
Administratör
FRANK Pirrone says
Hello, I added the code and clicked save. Nothing happened. Is there a publish button I need to press?
WPBeginner Support says
It would depend on the code you added as not all code has a visible component, you may also want to try clearing any caching on your site for another common reason for not seeing any change on a site.
Administratör
Jamie Turner says
Hi — Quick question. I’ve installed the plugin. Is there a way to select which pages the header and footer show up on? All I see is a global install without the ability to select pages. Thanks!
WPBeginner Support says
At the moment the plugin is for adding code to your site’s header and not showing/hiding your header. Your theme’s templates would decide where your header and footer show on your site.
Administratör
Pierre Patenaude says
I have installed the plugin (and it shows as being activated in the plugin list) but it doesn’t show up in the ”Settings” menu. Did I miss a step? Could you provide a solution?
Thanks
WPBeginner Support says
No, the option should be available once the plugin is active as long as you have access to edit the site’s settings, you would want to ensure you are an admin on the site and if it is still not visible you would want to try disabling your other plugins to see if it is possibly a conflict with one of those plugins.
Administratör
Ashleigh White says
Hi! I have a question! I am trying to add the global site tag and phone snippet to my code on each page so I can track my google ad calls. I have the ”Headers and Footers” plugin, can I just paste it here and I am good? Or does it matter where I post it (Header vs. Body. Footer)? Thanks so much!
WPBeginner Support says
For ad code, it is recommended to place the code in the header, you can see more about that in our article below:
https://www.wpbeginner.com/beginners-guide/how-to-add-google-adsense-to-your-wordpress-site/
Administratör
Deborah Dakota says
So close to being what’s needed! But Google strongly recommends using different metadata for every page. ”Identical or similar descriptions on every page of a site aren’t helpful when individual pages appear in the web results. In these cases we’re less likely to display the boilerplate text. Wherever possible, create descriptions that accurately describe the specific page. ” Please consider updating your plugin accordingly.
WPBeginner Support says
Our plugin is not for metadata, it is mainly for code to add things like Google Analytics tracking or for verification codes. If you want a plugin for adding metadata to individual posts, we would recommend taking a look at All in One SEO as that will give you far better control over your metadata
Administratör
Robert Zou says
I have a question. How do you remove code that you added using the insert headers and footers plugin? When I open up the theme editor I can’t find the code I added using this plugin.
WPBeginner Support says
Code added using the plugin would be removed when removed from the plugin’s settings or the plugin is uninstalled.
Administratör
James says
Hello, hey I added the plugin above to my site and added the code to the header section. Then I tested with your site and it said it was saved successfully.
But I don’t see the bot when I go to the live site. Could u tell me what I’m doing worng? Tnx.
WPBeginner Support says
It would depend on the specific code you are adding, we would recommend checking with the support for the code for if you added it correctly as not all code is made to have something visible.
Administratör
Emmanuel says
I wanted to change the color of my address bar using this plugin but each time I paste it gives me an error message
Is my code okay?
WPBeginner Support says
It would depend on the specific code and where the code is intended to be added. You would want to reach out to who you received the code from for where it should be placed.
Administratör
Elizabeth says
I bought a theme but it does not let me add any button action in the header nor in the menu, do you think this plugin could help me???
WPBeginner Support says
This plugin is for adding code such as scripts into the header, not for adding buttons. For an easy way to customize your design, you would want to take a look at page builders like the ones in our article below:
https://www.wpbeginner.com/beginners-guide/best-drag-and-drop-page-builders-for-wordpress/
Administratör
Ahmed says
How can add the code in the header as high as possible? I need to put Code first of few lines in the header. How can I control the position of the code?
Thanks
WPBeginner Support says
If you need a very specific location for the code, you would want to manually add the code to your files.
Administratör
William says
USELESS for a theme that does not have headers in the first place, like wordpress 2021. Useless.
It was implied that this plugin would do that. It. Does. Not. ALL it does in insert a GIANT version of the picture you choose ABOVE your menu and site name.
WPBeginner Support says
The 2021 theme does have a header but, the Insert Headers and Footers plugin is for inserting code such as Google Analytics, not for adding photos to the header of your website. We would not recommend using this plugin for adding a header image as that would cause the errors you are running into.
Administratör
Muhammad Shoaib says
Hey There,
I have already installed ”Insert Footer and Header plugin”, if I wanna to remove from site then the inserted code would also be removed from header section or still saved without plugin?
Kindly light me.
WPBeginner Support says
If you remove the plugin, the added code should be removed as well.
Administratör
Kirsten says
I’m being told by Google Analytics to add a Global Site Tag code immediately after the tag. Does this plugin do that? Otherwise, I have no idea how to add this code to *every* page on my site!
WPBeginner Support says
Yes, the plugin will add it to all of your pages with a header.
Administratör
Lisa Masquelier says
Thank you SO much for these simple instructions and the plug-in. I could not figure out why my website kept deleting from Pinterest!
WPBeginner Support says
Glad our guide was helpful!
Administratör
Kamlesh says
The Header and Footer in each blog post will be different? Is the Plugin for each Post?
WPBeginner Support says
Code added using the plugin will be on every post and page and not individual codes for individual posts and pages.
Administratör
Denise says
If I need to add code before the closing tag, which box do I put the code into?
WPBeginner Support says
You would place that code into the footer section
Administratör
Redentor mariano says
Thank you for some plug in that you shared.
I gonna try it into my site.
WPBeginner Support says
We hope our plugin helps you add code to your header
Administratör
Ana says
Thank you! Very helpful!
WPBeginner Support says
You’re welcome
Administratör
Trang says
Hey,
I can’t find the ”Insert Headers” section below my post’s editor? So how can I enable that function allowing me insert different code for specific post?
WPBeginner Support says
Our plugin is for the entire site at this time and not individual posts or pages.
Administratör
Emory says
How do I install different code for each page type instead of putting all the code in every page?
WPBeginner Support says
You would need to manually add that if we’re understanding what you’re wanting.
Administratör
Ali says
Is ”Insert Headers and Footers” plugin compatible with WordPress version 5.5.1?
WPBeginner Support says
Yes, we will look into updating the tested with version as soon as we are able
Administratör
Brian Small says
I am getting the following error when hitting SAVE from this plug-in:
A potentially unsafe operation has been detected in your request to this site
WPBeginner Support says
You would want to check if you have any security plugins active on your site or if your host has one set up. You may also want to ensure you copied the code you are attempting to add correctly.
Administratör
DAVE says
On your demonstration you didn’t have anything come up on the top.
This is the instructions from the code generator I am using;
Paste the copied code into bottom of your HTML page just before the closing tag
I tested the code and it does not work, ”Am I doing something different? ”
WPBeginner Support says
We would first recommend reaching out to the support of what has generated the code to ensure there isn’t anything specific about the code that needs to be set on your page for it to work correctly.
Administratör
DAVE says
Yes thank you, good idea.
James says
Hello. I need to edit the header code on a specific set of pages only. I have currently added the script I need to the header.php file, however this applies the code to all pages globally.
Is there any way I can add the script to a specific set of pages only?
WPBeginner Support says
Unless I hear otherwise, we do not have a recommended method for page specific code at this time.
Administratör
Susan says
Thank you so much!!!
This stuff scares me as I think I am going to doom my website forever!!
So easily explained will definitely be subscribing.
I need to work on this every day.
WPBeginner Support says
Glad our guides have been helpful
Administratör
Marc says
If my theme does not allow custom header images, will this plugin allow me to make custom header images. Lost on how to do this. We have an old theme with custom header function
WPBeginner Support says
This plugin is not for that at the moment. For customizing the design of your theme you may want to look into page builder plugins like the ones in our article below:
https://www.wpbeginner.com/beginners-guide/best-drag-and-drop-page-builders-for-wordpress/
Administratör
Mark says
Would i be able to use a relative path? so I can move the site to a different host without changing header? if so where is the origin?
i tried to include some some examples but sucuri blocked the post as malicious. i guess it doesn’t like seeing paths.
WPBeginner Support says
It would depend on the code but you should be able to user relative paths if you wanted.
Administratör
Alexandra says
Yaaaaaaay! I am so excited. I was having so much trouble getting my Mailchimp pop-up to work, but this plugin did the job easy-peasy!
WPBeginner Support says
Glad our recommendation could help
Administratör
Steve says
Hi, I have installed the Headers and Footers plugin and added code for the footer. The text that I want displayed is at the very bottom, below the Bento copyright line. Is there a way to have my footer appear at the top of the footer display? Thanks
WPBeginner Support says
For footer customizations, you would want to reach out to your theme’s support to see if they have any recommended options you can use.
Administratör
Subrat says
I have already put Google analytics code in the header section using insert header and footer plugin how can I add adsense code there again?
WPBeginner Support says
You would add the new code below the analytics code
Administratör
rooch says
How about using the functions.php file in child theme to add header and footer snippets
WPBeginner Support says
That would be something you can do but not all beginners want to or understand how to create a child theme, that is why we recommend this method.
Administratör
Ruhul says
This plugin’s activation active auto bulk mail sending from my hosting server. This is working like a spam. So I have to delete this from my website.
WPBeginner Support says
This plugin does not have anything like that, we would recommend scanning your site to ensure you do not have any malicious code on your site
Administratör
Tom says
I added this plugin to my site but nothing showed when I clicked on the plugin? I’m using an old version of WP but not sure if this is the reason why.
WPBeginner Support says
You should find the plugin’s section under Settings>Insert Headers and Footers
Administratör
Fazil Ibrahim Moihammed says
Hi team,
Does the FB Pixel Base Code was copied and paste on the header tag in that plugin.
will it automatically apply to every page of the website? Please reply!
WPBeginner Support says
Yes, the plugin will add the code to every page
Administratör
Anchal says
How can I add a code in body section (not in the header/footer section ) with this plugin?
I want to add certain code in the body section to avoid render blocking.
WPBeginner Support says
The plugin should currently have a third input box where you can include code that should be in the body of your site.
Administratör
firatba says
Thanks a lot! It helps me while adding our on-site messagin system code.
WPBeginner Support says
You’re welcome, glad it was helpful
Administratör
ANA LUIZA says
Very helpful! <3 Thank you!
WPBeginner Support says
You’re welcome
Administratör
Noya says
Hi,![:-)](data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E)
My site was built by a web developer who already included all sorts of code snippets in the section of my site.
If I add new snippets of code using this plugin, will it overwrite the code that’s already there or just add the new code to the existing code?
I don’t want to make a mess of my site…
Thanks!
WPBeginner Support says
If you add code using this plugin it would be added to your site, it would not replace code
Administratör
Arsalaan says
Nice explanation!
WPBeginner Support says
Thank you
Administratör
Wendy says
Hi! I tried to add the plugin to my site but you need to have a business page to add any plugins? Can I add the code without a plugin?
WPBeginner Support says
It sounds like your site is on WordPress.com, in which case you are limited to what WordPress.com allows. Our guides are for WordPress.org sites, you can see a comparison between the two here:
https://www.wpbeginner.com/beginners-guide/self-hosted-wordpress-org-vs-free-wordpress-com-infograph/
Administratör
anudeep says
hi
First i have install header and footer plugin than after past my google analytics code . but my problem is once past the code and see my website, the code showing disable? How to solve it?
WPBeginner Support says
If the code is not being added to your header, you would want to clear any caching on your site as that is the most common root of that issue.
Administratör
Shahad says
my header and footer in not showing in particular page..how can i solve it
WPBeginner Support says
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.
Administratör
Lio says
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 says
Not at the moment, for the time being, the plugin adds the code to all pages by default
Administratör
Keith says
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 says
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/
Administratör