Skip to content
Anand Kumar edited this page Jan 21, 2026 · 3 revisions

Header and Footer Scripts - User Guide

Header and Footer Scripts is a lightweight, powerful WordPress plugin that allows you to insert custom code (HTML, JavaScript, CSS) into your site's header, body, and footer areas without editing your theme files.

Table of Contents

  1. Installation
  2. Global (Site-wide) Scripts
  3. Per-Post/Page Scripts
  4. Permission Management
  5. Troubleshooting

Installation

  1. Go to your WordPress Dashboard.
  2. Navigate to Plugins > Add New.
  3. Search for "Header and Footer Scripts".
  4. Click Install Now and then Activate.

Alternatively, you can upload the plugin folder to your /wp-content/plugins/ directory.


Global (Site-wide) Scripts

You can add scripts that run on every page of your website from the plugin settings.

Navigate to: Settings > Header and Footer Scripts

Header Scripts

  • Location: Inside the <head> tag.
  • Usage: Best for verification tags (Google Search Console), CSS styles (<style>), and scripts that must load early (e.g., critical analytics).
  • Hook: wp_head

Body Scripts (New in v2.4.0)

  • Location: Immediately after the opening <body> tag.
  • Usage: Required for certain tracking pixels like Google Tag Manager (noscript part) or Facebook Pixel.
  • Hook: wp_body_open
  • Note: Your theme must support the wp_body_open() function (standard in most modern themes since WP 5.2).

Footer Scripts

  • Location: Just before the closing </body> tag.
  • Usage: The best place for most JavaScript (Google Analytics, Chat widgets, etc.) to prevent slowing down your page load speed.
  • Hook: wp_footer

Syntax Highlighting

The settings page includes a code editor with syntax highlighting, line numbers, and error checking to help you write valid code.


Per-Post/Page Scripts

You can inject a specific script into the Header of a single Post or Page.

  1. Edit any Post or Page.
  2. Scroll down to the "Insert Script to " meta box.
  3. Paste your specific CSS or JS code.
  4. Update/Publish the post.

Currently, per-post scripts are only supported for the Header section.


Permission Management

Security is a priority. Loading raw scripts allows executing arbitrary code (XSS), so access is restricted by default.

Who can add scripts?

  • Default: Only Administrators (or users with the unfiltered_html capability).
  • Granular Control: You can grant access to trusted Authors and Contributors.

How to configure access:

  1. Go to Settings > Header and Footer Scripts.
  2. Look for the "Who can insert scripts?" section.
  3. Check "Allow Authors" or "Allow Contributors".
  4. Save settings.

Warning

Security Notice: Granting this permission adds the unfiltered_html capability to that role. This allows those users to post raw HTML/JS anywhere on the site (not just in this plugin). Only enable this for trusted users.


Troubleshooting

Scripts not appearing?

  1. Clear Cache: If you use a caching plugin (WP Rocket, W3 Total Cache), clear the cache after saving scripts.
  2. Check Theme Support:
    • For Header scripts, your theme header.php must contain <?php wp_head(); ?>.
    • For Body scripts, your theme header.php must contain <?php wp_body_open(); ?> just after the <body> tag.
    • For Footer scripts, your theme footer.php must contain <?php wp_footer(); ?>.
  3. Syntax Errors: Check if your JS code has errors. The built-in editor usually highlights these. Ensure you wrap JS in <script> tags and CSS in <style> tags.

"Cheatin' uh?" message?

You do not have permission to edit scripts. Ensure you are an Administrator or have been granted access via the settings.