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

Så här addar du kod för Header och Footer i WordPress (på det enkla sättet)

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.

How to Add Header and Footer Code in 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:

  1. Manuellt, genom att editera ditt temas header.php och footer.php filer
  2. Med ditt temas built-in header- och footer-kodfunktion
  3. 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

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

Subscribe to WPBeginner

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.

Add code to header and footer with WPCode

Om du rullar ner ser du också en box för ”Body” och en box för ”Footer”.

Header and footer script boxes WPCode

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.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

267 kommentarerLämna ett svar

  1. Syed Balkhi

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

      Administratör

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

      Administratör

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

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

      Administratör

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

      Administratör

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

      Administratör

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

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

      Administratör

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

      Administratör

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

  11. moschino

    pls can i use both facebook tracking pixel and google analytics on a single wp page?

    • WPBeginner Support

      Yes, you can.

      Administratör

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

      Administratör

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

      Administratör

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

      Administratör

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

      Administratör

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

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

      Administratör

  18. Marcus

    Hi,

    After I insert the Header code, when I click ”save”, will auto link to Page 404 error. How can I fix it?

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

      Administratör

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

      Administratör

        • WPBeginner Support

          You’re welcome :)

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

      Administratör

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

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

      Administratör

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

      Glad our article was helpful :)

      Administratör

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

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

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

      Administratör

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

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

      Administratör

      • 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

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

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

      add_filter( 'disable_ihaf_header', 'hide_header_on_page_id' );
      function hide_header_on_page_id() {
        if( is_page( 65 ) ) {
          return false;
        }
        return true;
      }
      

      Administratör

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

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

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

  34. Claire Plaisted

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

  35. Iboro William

    This has been quite helpful!

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

  37. Alex

    Hello, is there a way to insert header code only to certain posts or to posts in a certain category?

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

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

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

      Administratör

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

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

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

  44. Gareth Parmar

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

  45. Brandon

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

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

          if (is_page( 22 )) { 
          // your code goes here
          } 
          

          Don’t forget to replace 22 with your actual page ID.

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

  47. Prava

    im a new leaner and im facing problem in converting footer content in to dynamic wordpress content

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

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

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

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.