Skip to main content

Wagtail Header & Footer Scripts

A reusable Wagtail app for managing header and footer scripts across different sites using Wagtail Settings. It also supports adding page-specific header and footer scripts.

Features

  • Add header/footer scripts per site
  • Add header/footer scripts specific to individual pages
  • Use Wagtail settings and model clustering
  • Toggle scripts on/off
  • Render scripts using custom template tags
  • Supports easy integration into Wagtail pages via models

Installation

pip install wagtail-headers-footers

Add to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "wagtail.contrib.settings",
    "wagtail_headers_footers",
]

Add context processor to your settings

TEMPLATES = [
    {
        ...
        "OPTIONS": {
            "context_processors": [
                ...
                "wagtail.contrib.settings.context_processors.settings",
            ],
        },
    },
]

Migrate Wagtail H/F

python manage.py migrate wagtail_headers_footers

Usage

Add Site-wide scripts

Go to Settings > Headers & Footers in the Wagtail Admin to manage your scripts.

Wagtail Admin Screenshot

Add page-specific scripts

For page-specific headers and footers, you can add them by inheriting the following in your page models:

from wagtail.models import Page
from wagtail_headers_footers.models import PageHeaderFooterScriptsMixin

class HomePage(PageHeaderFooterScriptsMixin, Page):
    content_panels = Page.content_panels + PageHeaderFooterScriptsMixin.header_footer_panels

Don't forget to make migrations and migrate if neccessory.

Go to Pages in the Wagtail Admin to manage your page-specific scripts.

Wagtail Admin Page Screenshot

Add to your templates

Add the following code to your base template where you want to render the scripts:

{% load header_footer_tags %}

<head>
	...
    {% render_header_scripts %}
	...
</head>
<body>
    ...
    {% render_footer_scripts %}
	...
</body>

This will render both the site-wide and page-specific header/footer scripts dynamically.

Testing

python -m unittest discover tests

License

MIT

Metadata

Release files for wagtail-headers-footers 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtail-headers-footers 0.1.3
File Size Uploaded
wagtail_headers_footers-0.1.3.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-headers-footers 0.1.3
File Interpreter ABI Platform
wagtail_headers_footers-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / wagtail_headers_footers-0.1.3.tar.gz

Download URL wagtail_headers_footers-0.1.3.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2ec240ebfa185c33266c9770f83432f282c207c9a5ecf72ebbedcd3a64657260
BLAKE2b-256 checksum
How to use checksums
3c83f3a9eb58efa3874caac717cdbb6ebdc8db5b217e7c5685c5926e7f728b21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release files / wagtail_headers_footers-0.1.3-py3-none-any.whl

Download URL wagtail_headers_footers-0.1.3-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed922bbf044f1357e9e7184c041d81faf40518608c0976d8662ac960cebcc78d
BLAKE2b-256 checksum
How to use checksums
4ffa236718571d3d2de492cbb73df8bd02b1688b78c71397b37a93ae2f314fd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page