{"id":86231,"date":"2022-06-13T12:27:00","date_gmt":"2022-06-13T17:27:00","guid":{"rendered":"https:\/\/wpengine.com\/?post_type=resource&#038;p=86231"},"modified":"2024-01-18T10:21:19","modified_gmt":"2024-01-18T16:21:19","slug":"wordpress-header-and-footer-code","status":"publish","type":"resource","link":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/","title":{"rendered":"Adding Code to A WordPress Header or Footer"},"content":{"rendered":"\n<p>For a wide variety of reasons, it\u2019s possible that at some point you will want or need to add code to your WordPress site\u2019s header or footer. Unfortunately, the platform doesn\u2019t provide a simple or straightforward way to do this out of the box.<\/p>\n\n\n\n<p>The good news is that you can easily remedy this with the help of a child theme and your <em>functions.php <\/em>file, or a WordPress plugin. Whichever method you choose, you\u2019ll be able to easily enhance your site with custom features, user data, and performance-boosting strategies.<\/p>\n\n\n\n<p>In this post, we&#8217;ll explain a few cases in which you might need or want to add code to your WordPress site&#8217;s header and footer. Then we&#8217;ll share step-by-step instructions for two methods that enable you to edit these elements to create a custom header or footer. Let&#8217;s get started!<\/p>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Why Edit Your WordPress Header and Footer Code?<\/h2>\n\n\n\n<p>The reasons you may want to edit your WordPress header or footer are many and varied. Probably the most obvious is that sometimes you want to style your site through the use of custom code, and need a way to add this code to your header and\/or footer.<\/p>\n\n\n\n<p>However, these are also prime locations for tracking codes, such as the one used for Google Analytics. These codes can provide valuable information on user behavior to enhance your marketing and content strategies.<\/p>\n\n\n\n<p>Additionally, WordPress does not include <a href=\"https:\/\/codex.wordpress.org\/Meta_Tags_in_WordPress\" target=\"_blank\" rel=\"noreferrer noopener\">meta tags<\/a> by default. These are added to your site\u2019s header to help search engines crawl your pages. Though they\u2019re <a href=\"https:\/\/torquemag.io\/2018\/11\/seo-tactics-that-no-longer-work\/\" target=\"_blank\" rel=\"noreferrer noopener\">not as relevant now<\/a> as they used to be, there\u2019s no harm in adding them to your header \u2013 they can only help your site\u2019s visibility.<\/p>\n\n\n\n<p>Lastly, you may be familiar with the practice of <a href=\"https:\/\/wpengine.com\/resources\/remove-render-blocking-javascript-css-wordpress\/\" target=\"_blank\" rel=\"noreferrer noopener\">moving render-blocking JavaScript<\/a> \u2018below the fold\u2019. This typically means adding it to your WordPress footer, which will require editing its code. This technique can help improve your site\u2019s performance by decreasing loading times.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Add Code to Your WordPress Header or Footer Manually (In 2 Steps)<\/h2>\n\n\n\n<p>There are two primary methods for adding code to your WordPress header or footer. The first is to manually edit your site\u2019s theme, and the second is to use a plugin. Though manually editing your theme\u2019s files is more risky and difficult, for some more advanced users it\u2019s the preferred method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create a Child Theme<\/h3>\n\n\n\n<p>Manually adding code to your WordPress header or footer involves editing some of your theme\u2019s files. When you have to do this, it\u2019s always wise to edit <a href=\"https:\/\/wpengine.com\/resources\/create-child-theme-wordpress\/\" target=\"_blank\" rel=\"noreferrer noopener\">a child theme<\/a> instead of messing with your parent theme\u2019s files directly. This way, you can avoid losing your changes when you update your theme.<\/p>\n\n\n\n<p>Fortunately, the process to <a href=\"https:\/\/developer.wordpress.org\/themes\/advanced-topics\/child-themes\/\" target=\"_blank\" rel=\"noreferrer noopener\">create a child theme<\/a> manually is pretty simple, and you can access the WordPress tutorials you&#8217;ll need to customize headers. However, if you need to create a child theme in a pinch, a theme builder plugin such as <a href=\"https:\/\/wordpress.org\/plugins\/child-theme-configurator\/\" target=\"_blank\" rel=\"noreferrer noopener\">Child Theme Configurator<\/a> can help.<\/p>\n\n\n\n<p>With a theme builder plugin you can easily generate a child theme with the click of a button, although the fully manual approach could be just as quick once you have the method down.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Edit Your Child Theme\u2019s <em>functions.php<\/em> File<\/h3>\n\n\n\n<p>Once your child theme is set up, you\u2019ll need to access and edit its <em>functions.php<\/em> file. Before you start, it\u2019s always wise to back up your site, just in case you make any mistakes and want to easily restore to a previous state.<\/p>\n\n\n\n<p>The usual way to edit your <em>functions.php <\/em>file is via <a href=\"https:\/\/wordpress.org\/support\/article\/using-filezilla\/\" target=\"_blank\" rel=\"noreferrer noopener\">File Transfer Protocol (FTP)<\/a> and an FTP client such as <a href=\"https:\/\/filezilla-project.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">FileZilla<\/a>. However, you can also edit certain files from your WordPress dashboard. To access it, navigate to <em>Appearance &gt; Theme Editor<\/em>.<\/p>\n\n\n\n<p>You\u2019ll receive <a href=\"https:\/\/wptavern.com\/wordpress-4-9-protects-users-from-fatal-errors-created-in-the-theme-and-plugin-editors\" target=\"_blank\" rel=\"noreferrer noopener\">a warning<\/a> that you\u2019re about to edit your theme\u2019s files \u2013 click the <em>I Understand<\/em> button to proceed. Next you\u2019ll want to make sure you have the correct file selected. In the sidebar to the right of the site editor, make sure <em>Theme Functions (functions.php) <\/em>is selected.<\/p>\n\n\n\n<p>Now you can add your custom code at the end of this file, and click on <em>Update File <\/em>when you\u2019re finished.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Add Code to Your WordPress Header or Footer With a Plugin (In 2 Steps)<\/h2>\n\n\n\n<p>While in some cases it may be easier to manually edit your WordPress theme\u2019s files to add code to your footer or header section, using a plugin is usually the safer route. For the purposes of this article, we\u2019ll be using one of the most popular and highly rated plugins for the task, <a href=\"https:\/\/wordpress.org\/plugins\/header-footer\/\" target=\"_blank\" rel=\"noreferrer noopener\">Header, Footer and Post Injections<\/a>.<\/p>\n\n\n\n<p>However, there are many plugins available in the <a href=\"https:\/\/wordpress.org\/plugins\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress Plugin Directory<\/a> and elsewhere that can help with this task. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Install and Activate Your Plugin of Choice<\/h3>\n\n\n\n<p>For starters, you\u2019ll need to <a href=\"https:\/\/wordpress.org\/support\/article\/managing-plugins\/#finding-and-installing-plugins\" target=\"_blank\" rel=\"noreferrer noopener\">install and activate<\/a> the plugin you wish to use. You can do this by downloading the plugin\u2019s <em>.zip<\/em> file from the Plugin Directory or another online marketplace and then uploading it to your site. Alternatively, navigate to <em>Plugins &gt; Add New<\/em> in your dashboard.<\/p>\n\n\n\n<p>Here you can search for the footer or header plugin you wish to use. Whichever method you choose, you\u2019ll finish this step by clicking on the <em>Install<\/em> button, then <em>Activate<\/em> when the option is presented.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Add Your Code Snippets to Header, Footer and Post Injections<\/h3>\n\n\n\n<p>Once the plugin is installed, you should be able to navigate to <em>Settings &gt; Header and Footer<\/em> in your dashboard.<\/p>\n\n\n\n<p>Here you\u2019ll find a text editor for adding code snippets \u2013 such as a Google Analytics tracking code or custom JavaScript \u2013&nbsp;you wish to include in your header and\/or footer.<\/p>\n\n\n\n<p>There\u2019s a lot you can accomplish on this page. In the first two fields you can add code to your header section. The left-hand field adds the code to every page on your site \u2013 this is useful for Google Analytics, for example. The right-hand field will add the code only to your home page.<\/p>\n\n\n\n<p>The next fields add code to the body and footer code of your pages. The fields on the left are for desktop viewing, while the ones on the right are for mobile versions of your code. Once you\u2019re done editing, don\u2019t forget to click on the <em>Save<\/em> button at the bottom of the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Improve Your Site\u2019s Experience With WP Engine<\/h2>\n\n\n\n<p>There&#8217;s no doubt you want your WordPress website to provide a top notch digital experience to your users. Adding code to your WordPress footer or header is a useful tactic for customizing your site, implementing Google Analytics, or improving performance.<\/p>\n\n\n\n<p>At WP Engine, we serve developers, from our top-notch <a href=\"https:\/\/wpengine.com\/wordpress-hosting\/\" target=\"_blank\" rel=\"noreferrer noopener\">WordPress hosting<\/a> to the wide variety of <a href=\"https:\/\/developer.wordpress.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">developer resources<\/a> that can help you take your WordPress website\u2019s experience to new heights. Check them out today!<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For a wide variety of reasons, it\u2019s possible that at some point you will want or need to add code to your WordPress site\u2019s header or footer. Unfortunately, the platform doesn\u2019t provide a simple or straightforward way to do this out of the box. The good news is that you can easily remedy this with<span class=\"tile__ellipses\">&hellip;<\/span><span class=\"tile__ellipses--animated\"><\/span><\/p>\n","protected":false},"author":297,"featured_media":131704,"template":"","resource-topic":[913,904,912,910,901],"resource-role":[895,896,897],"resource-type":[916],"class_list":["post-86231","resource","type-resource","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Edit WordPress Header or Footer | WP Engine\u00ae<\/title>\n<meta name=\"description\" content=\"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.\" \/>\n<meta name=\"robots\" content=\"noindex, follow\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Edit WordPress Header or Footer | WP Engine\u00ae\" \/>\n<meta property=\"og:description\" content=\"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Engine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/wpengine\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-18T16:21:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2019\/12\/shutterstock_2009931089.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@wpengine\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/\",\"url\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/\",\"name\":\"How to Edit WordPress Header or Footer | WP Engine\u00ae\",\"isPartOf\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\"},\"datePublished\":\"2022-06-13T17:27:00+00:00\",\"dateModified\":\"2024-01-18T16:21:19+00:00\",\"description\":\"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.\",\"breadcrumb\":{\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wpengine.com\/case-studies\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Resources\",\"item\":\"https:\/\/wpengine.com\/case-studies\/resources\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Adding Code to A WordPress Header or Footer\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#website\",\"url\":\"https:\/\/wpengine.com\/case-studies\/\",\"name\":\"WP Engine\",\"description\":\"Managed Hosting for WordPress\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/3a22232b01de39dcf588fb8e421c0521\",\"name\":\"Erin Myers\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cd881e115bc28c81642ec61752db9981ece9ee8b4c81498a9b6276b9cdcaf5e6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cd881e115bc28c81642ec61752db9981ece9ee8b4c81498a9b6276b9cdcaf5e6?s=96&d=mm&r=g\",\"caption\":\"Erin Myers\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Edit WordPress Header or Footer | WP Engine\u00ae","description":"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.","robots":{"index":"noindex","follow":"follow"},"og_locale":"en_US","og_type":"article","og_title":"How to Edit WordPress Header or Footer | WP Engine\u00ae","og_description":"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.","og_url":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/","og_site_name":"WP Engine","article_publisher":"https:\/\/www.facebook.com\/wpengine","article_modified_time":"2024-01-18T16:21:19+00:00","og_image":[{"width":1100,"height":500,"url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2019\/12\/shutterstock_2009931089.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_site":"@wpengine","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/","url":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/","name":"How to Edit WordPress Header or Footer | WP Engine\u00ae","isPartOf":{"@id":"https:\/\/wpengine.com\/case-studies\/#website"},"datePublished":"2022-06-13T17:27:00+00:00","dateModified":"2024-01-18T16:21:19+00:00","description":"Customize your WordPress header or footer by adding code either manually or with plugins. Learn more about editing WordPress and build the perfect website.","breadcrumb":{"@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wpengine.com\/case-studies\/resources\/wordpress-header-and-footer-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wpengine.com\/case-studies\/"},{"@type":"ListItem","position":2,"name":"Resources","item":"https:\/\/wpengine.com\/case-studies\/resources\/"},{"@type":"ListItem","position":3,"name":"Adding Code to A WordPress Header or Footer"}]},{"@type":"WebSite","@id":"https:\/\/wpengine.com\/case-studies\/#website","url":"https:\/\/wpengine.com\/case-studies\/","name":"WP Engine","description":"Managed Hosting for WordPress","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wpengine.com\/case-studies\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/3a22232b01de39dcf588fb8e421c0521","name":"Erin Myers","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wpengine.com\/case-studies\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cd881e115bc28c81642ec61752db9981ece9ee8b4c81498a9b6276b9cdcaf5e6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd881e115bc28c81642ec61752db9981ece9ee8b4c81498a9b6276b9cdcaf5e6?s=96&d=mm&r=g","caption":"Erin Myers"}}]}},"acf":[],"grid_image_url":"https:\/\/wpengine.com\/case-studies\/wp-content\/uploads\/2019\/06\/shutterstock_773419579.jpg","media-type":{"term_id":916,"name":"Article","slug":"article"},"role":"<strong>Roles:<\/strong> Agency, Developer, Freelancer","topic":"<strong>Topics:<\/strong> Analytics, Marketing, Performance, SEO, WordPress","_links":{"self":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource\/86231","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource"}],"about":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/types\/resource"}],"author":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/users\/297"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media\/131704"}],"wp:attachment":[{"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/media?parent=86231"}],"wp:term":[{"taxonomy":"resource-topic","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-topic?post=86231"},{"taxonomy":"resource-role","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-role?post=86231"},{"taxonomy":"resource-type","embeddable":true,"href":"https:\/\/wpengine.com\/case-studies\/wp-json\/wp\/v2\/resource-type?post=86231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}