Header/Footer Code Injector (CSS/JS): complete guide
Install, configure and use CSS/JS/HTML code injection: locations, page targeting, test mode, duplication and multistore for PrestaShop 8 and 9.
Overview
The Header/Footer Code Injector adds CSS, JavaScript or HTML code to your PrestaShop store without editing the theme files. Each block of code is a snippet managed from the back office, with its own location, target pages, injection order and status.
Common uses: Google Tag Manager, Google Analytics, Meta Pixel, verification tags (Search Console, Pinterest), custom CSS, chat widget.
Installation
- Download the
dfcodeinjector.ziparchive from your DataFirefly account. - In the back office, open Modules > Module Manager, click Upload a module and drop the archive.
- Click Configure to open the snippet list.
Compatible with PrestaShop 8.0 to 9.x and multistore. Interface available in French, English, Spanish, German, Italian, Dutch, Polish and Portuguese.
Upgrading from version 1.0.0
Upload the new archive through the Module Manager: the upgrade runs automatically and your snippets are kept. A snippet that was limited to some pages switches to the Only the selected pages targeting, the others to All pages.
Create a snippet
In the list, click Add a snippet.
Form fields
- Name: internal name, for example “Google Tag Manager”.
- Location: where the code is injected (see below).
- Code: the complete code, tags included. It is injected as is. In this field, Tab inserts 4 spaces; press Escape then Tab to move to the next field.
- Targeting, Pages and Other pages: the pages the snippet applies to.
- Order: injection order within a location. When left empty, the snippet is placed last.
- Test mode: limits injection to the maintenance IP addresses.
- Active: enables or disables the snippet without deleting it.
- Store (multistore only): all stores or a single one.
The three locations
- Header (head tag): styles, meta tags, verification tags, main GTM script. Hook
displayHeader. - Body start: right after the opening body tag, for the GTM noscript part. Hook
displayAfterBodyOpeningTag. - Body end: right before the closing body tag, for tracking and chat scripts. Hook
displayBeforeBodyClosingTag.
If your theme does not call the body start or body end hooks, the module inserts the code directly into the final page HTML at the same spot (hook actionOutputHTMLBefore). All three locations therefore work with every theme, with no setting required.
Page targeting
The Targeting field offers three modes: All pages, Only the selected pages, or All pages except the selected ones.
The Pages list holds 30 PrestaShop pages: home, category, product page, CMS, search, cart, checkout, order confirmation, login, my account, order history, contact, 404 page and more. The Other pages field accepts other technical page names, separated by commas. For a module page, the format is module-modulename-controller.
To find the technical name of a page, view its source: in the Classic theme and its derivatives, it is the id attribute of the body tag.
Test mode
A snippet in test mode is only injected for the IP addresses entered in Shop Parameters > General > Maintenance (maintenance IP field). CIDR ranges are accepted. You can check a tag on the live store without any visitor receiving it, then switch test mode off to publish it.
Duplicate a snippet
The menu of each row in the list offers Duplicate. The copy is created disabled and placed last: review it before enabling it.
Examples
Google Tag Manager
GTM needs two snippets:
- “GTM head”, location Header, with the first script provided by Google:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){ ... })(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
- “GTM body”, location Body start, with the noscript part provided by Google.
Conversion pixel
Location Body end, targeting Only the selected pages, page Order confirmation. The pixel only fires after a purchase.
Custom CSS
Location Header, CSS wrapped in a style tag:
<style>
.header-banner { background:#0f172a; color:#fff; }
</style>
Verification tag
For Search Console or a social network, location Header:
<meta name="google-site-verification" content="YOUR_CODE" />
Multistore
With multistore enabled, the Store field serves a snippet on all stores or on a single one. On a single-store install, the field is hidden and the snippet applies to the whole store.
Troubleshooting
- The code does not appear: check that the snippet is active, that test mode is off (or that your IP is in the maintenance IPs) and that the current page matches the targeting.
- A full-page cache module is installed: clear its cache after each snippet change.
- The snippet does not show on a module page: check the technical name entered in Other pages, it must match the page name exactly.
- Two scripts run in the wrong order: adjust the Order field.
The code is injected without any filtering. Check its syntax (properly closed tags) and use test mode before enabling it on a production store.