It removes the need to add custom snippets to your theme’s functions.php file. If you are simply needing to add different PHP functions on a site-wide basis, we also recommend checking out the free Code Snippets plugin. To do it, head to the AMP tab in Header and Footer and paste your code snippet into the appropriate box: Google AMP interface BONUS – Add Code to Header and Footer of Google AMP PagesĪnother neat thing about this plugin is that, if you’re using Google AMP for WordPress, the plugin lets you specifically add code snippets to the header and footer of the Google AMP versions of your pages ( as long as you’re using the official AMP plugin from Automattic). If needed, you can add multiple code snippets to each box. If you just want to add a code snippet to the footer section for all users, no matter their devices, paste it in the Desktop box and leave Mobile unchecked: Example of adding code to footer Mobile – when checked, this lets you add a different code snippet to the mobile version of your site.Desktop – despite the name, this adds code to the footer of both the desktop and mobile version of your site unless you specifically check the box for Mobile.Again, you have two options, though they’re different from the header section: To add code to your site’s footer, you can scroll down to the BEFORE THE CLOSING TAG (FOOTER) option. Only home page – only adds the code snippet to the header of your homepage.įor example, to add the Google Analytics tracking code to WordPress, you’d just paste it into the Every page box and save your changes: Example of adding code to header.This is what you’ll want to use most of the time. Every page – adds the code snippet to the header of every single page on your site.To add code to your site’s header, you need to paste it into one of the boxes under the SECTION INJECTION area: But for this guide, you’ll mostly work in the default Head and footer tab: Head, Footer and Post Injections interface You’ll see a number of tabs in the plugin’s interface. Once you activate the plugin, you can access its interface by going to Settings → Header and Footer in your WordPress dashboard. Step 2: Add Code Snippet to Head, Footer and Post Injections Head, Footer and Post Injections is available for free at, so you can install and activate it directly from your WordPress dashboard by going to Plugins → Add New and searching for it: Header and Footer WordPress plugin Step 1: Install and Activate Head, Footer and Post Injections It currently has over 200,000 active installs with a 5 out of 5-star rating. While there are several plugins that offer this functionality, we recommend the Head, Footer and Post Injections plugin from Stefano Lissa because it gives you more control than many of the alternatives. The plugin is more beginner-friendly because it doesn’t require digging into the code.The plugin makes it easy to only add code snippets to the header or footer of your homepage, which can be helpful in some use cases.Your code snippets will remain intact if you ever switch themes.The benefits of using a plugin over the manual method in the next section are: Let’s say you want to customize WordPress, and while searching the web, you see a PHP snippet that you need to copy and paste into your installation.How to Add Code to WordPress Header and Footer With a Pluginįor most users, the easiest way to add code to the WordPress header and footer is via a plugin. With these functions, WPCode provides a framework in which you can fit most of the WordPress customizations. There’s also a section where you can add a header and footer code. When you download and install WPCode, you’ll get an interface from which you can search for commonly used snippets, enable and disable them individually, convert them into shortcodes, and more. So if you use a plugin to manage your WordPress snippets, I suggest you use the WPCode plugin. However, it’s not within everyone’s comfort zone to create a custom plugin, particularly considering that if you configure it wrong, it can break your site. Here at NameHero, we recommend using a custom plugin to paste your code snippets because it’s fully under your control and causes less bloat than plugins in the WordPress repository.
0 Comments
Leave a Reply. |