Script Injector is a lightweight WordPress plugin that allows you to easily insert custom scripts (like Google Analytics, Facebook Pixel, Google Tag Manager, etc.) into your website's header, body, or footer.
- Header Scripts: Insert scripts into the
<head>section of your site. - Body Scripts: Insert scripts immediately after the opening
<body>tag. - Footer Scripts: Insert scripts into the
<footer>section of your site. - Permission Check: Only users with
manage_optionscapability can access the settings page. - Clean Execution: Scripts are injected using standard WordPress hooks (
wp_head,wp_body_open,wp_footer).
This plugin is engineered for minimal overhead:
- Admin/front-end code isolation: Admin code (settings, menus, rendering) is never loaded on public pages.
- Single DB query: Only one
get_optioncall per request on the front-end. - Early bail-out: If no scripts are configured, the plugin exits immediately — zero hooks registered.
- Conditional hooks: Only hooks for non-empty script fields are registered.
- Zero global functions: All logic uses closures, avoiding namespace pollution.
- Upload the
script-injectorfolder to the/wp-content/plugins/directory. - Activate the plugin through the 'Plugins' menu in WordPress.
- Access the settings via Settings → Scripts.
- Go to the Scripts settings page.
- Paste your script code (e.g.,
<script>...</script>) into the corresponding field (Header, Body, or Footer). - Click "Save Changes".
- WordPress 5.2+ (for
wp_body_opensupport) - PHP 7.0+