How to add custom code in header / footer

Custom coding in WordPress allows you to extend and modify the functionality of your WordPress website beyond what can be achieved with standard themes and plugins. You can add custom features, integrate third-party services, or make design changes to suit your specific needs. Here are some common scenarios where custom coding is useful:

  1. Theme Customization: You may want to customize an existing theme to match your branding or to add specific design elements. To do this, you can create a child theme and modify its templates, stylesheets, and functions.
  2. Plugin Development: Sometimes, the available plugins don’t provide the exact functionality you need. In such cases, you can develop your own custom plugins. These can range from simple widgets to complex features.
  3. Custom Post Types and Taxonomies: If you have content that doesn’t fit neatly into standard posts or pages, you can create custom post types and taxonomies to organize and display it as needed.
  4. Custom Page Templates: You can create custom page templates for different sections of your site. For instance, a unique template for your blog, a different one for your portfolio, and so on.
  5. Custom Widgets: Develop custom widgets to display specific information or functionality in your site’s sidebar or other widgetized areas.
  6. Shortcodes: Create custom shortcodes to easily embed custom functionality or elements within your content.
  7. Hooks and Filters: WordPress provides hooks and filters that allow you to modify the behavior of existing themes and plugins without altering their code directly.
  8. Security Enhancements: Implement security measures such as user authentication, data validation, and protection against common web vulnerabilities like SQL injection and cross-site scripting (XSS).
  9. API Integration: Integrate third-party services or APIs to enhance the functionality of your website. For example, you could integrate a payment gateway, social media feeds, or a CRM system.
  10. Performance Optimization: Implement performance improvements such as caching, lazy loading, and asset optimization to ensure your site loads quickly and efficiently.

When custom coding in WordPress, it’s essential to follow best practices, use proper coding standards, and keep your code organized and well-documented. Additionally, consider using version control systems like Git to track changes and ensure collaboration is smooth if you’re working with a team.

Remember that custom coding can be complex, and if you’re not comfortable with PHP, HTML, CSS, and JavaScript, you may want to consider hiring a WordPress developer or agency to assist you in achieving your customization goals.


WordPress is a CMS where we mainly work on menus. It is not recommendable to go to coding part of CMS because this is not how CMS should be handled and a minor issue could break the whole code of website. There are a lot of services provided by google, etc. which needs tracking code added in header or a script added in footer. Or even if you want to add additional functionality in WordPress, you can add script through a plugin. This avoid you from going in the CMS code directly. While we recommend that only already tested code should be added here or some tracking code provided by a genuine source. This plugin is a great use to work directly inside CMS and quickly. No need to go in code and work on complicated coding. This plugin provides you three empty text areas to add header, body and footer.


  • Add tracking code/google ads code/etc. in header.
  • There are needs to quickly add CDN link/JavaScript/jQuery code in header/footer to fix and handle things.
  • We may also need to add CSS code in header or body of website.
  • There are requirements for many website owners to track their websites as demanded by various google and other online services. So, they can quickly and safely add code here.
  • Experts need it to add new functionalities and fix issues which otherwise don’t work in WordPress because of limited access in WordPress special files.

Risky other methods to add custom code:

1) Go to Appearance > Theme editor and search file named header.php/footer.php, however many themes have kept these files complex and adding custom code may not work directly in header or footer file.

2) Download File manager app, go to cPanel file manager or use FTP and search files of WordPress. You may want to create new file for JavaScript and link it to your website through functions.php file. These methods sometimes fail to work because of complexity and other restrictions of WordPress.

Other methods mentioned above need time and coding skills. It is not advised to use ‘Other’ methods if you are not an expert in WordPress because it can cause serious issues in website.

There are server or cache issues which don’t allow the editing in website to display on live website. One may incur theme coding standards/restriction which shall not directly allow to code in theme files, as per the requirement.

There is also high risk for an owner to mess up file structure and other code in WordPress files which can make website to stop work or causes issues. In case you are not an expert and don’t want to use risky other methods and don’t want to waste so much time, etc., try the DIY quick method given below:

3) Use a ready-made WordPress plugin to add code directly in header/body/footer of WordPress website. You will find it is quick to do through this plugin, with proper instructions mentioned: