PHPackages                             heimrichhannot/contao-head-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. heimrichhannot/contao-head-bundle

ActiveContao-bundle[Utility &amp; Helpers](/categories/utility)

heimrichhannot/contao-head-bundle
=================================

This module contains enhancements for the contao frontend page &lt;head&gt; region.

2.0.0(1mo ago)27.0k↑106.3%1[1 issues](https://github.com/heimrichhannot/contao-head-bundle/issues)5LGPL-3.0-or-laterPHPPHP ^8.2CI passing

Since Sep 12Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/heimrichhannot/contao-head-bundle)[ Packagist](https://packagist.org/packages/heimrichhannot/contao-head-bundle)[ RSS](/packages/heimrichhannot-contao-head-bundle/feed)WikiDiscussions v2 Synced today

READMEChangelog (10)Dependencies (31)Versions (61)Used By (5)

Contao Head bundle
==================

[](#contao-head-bundle)

[![](https://camo.githubusercontent.com/88645b0f5a2b492e560ab4d2afe702a78649bd1785d533464f9a16889f184238/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6865696d7269636868616e6e6f742f636f6e74616f2d686561642d62756e646c652e737667)](https://packagist.org/packages/heimrichhannot/contao-head-bundle)[![](https://camo.githubusercontent.com/73920fa0c3560e9f18a53e9180a44e973426966c627901f58e0767b99b6aec15/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6865696d7269636868616e6e6f742f636f6e74616f2d686561642d62756e646c652e737667)](https://packagist.org/packages/heimrichhannot/contao-head-bundle)

Enhance your website's SEO and social media presence with more meta- and structured data.

Features
--------

[](#features)

- Set open graph tags like og:title, og:description, og:url and og:image
- Provide a nice api to set head tags like meta, title, base, link
- Provide additional schema.org json-ld data
- Sets important meta tags like og:title, og:description, og:url and twitter:card out of the box
- Allow setting open graph and twitter fallback image on root page
- Allow setting twitter author per root page

Usage
-----

[](#usage)

### Setup

[](#setup)

1. Install with composer
2. Update your database
3. Optional: Set fallback image and twitter author in root page(s)

### Add additional meta tags

[](#add-additional-meta-tags)

In your root page, you can activate to add fallback image (og:image) and X/Twitter username (twitter:site) meta tags to you web page.

[![Screenshot Meta Data Settings](docs%2Fimg%2Fscreenshot_backend_meta_data.png)](docs%2Fimg%2Fscreenshot_backend_meta_data.png)

### Add additional schema.org data

[](#add-additional-schemaorg-data)

In your root page, you can activate additional structured data for your web page. Following schema.org types are available:

- @Organization
- @WebSite

[![Screenshot Structured Data Settings](docs%2Fimg%2Fscreenshot_backend_structured_data.png)](docs%2Fimg%2Fscreenshot_backend_structured_data.png)

### Add (meta-)tags from template (twig)

[](#add-meta-tags-from-template-twig)

The bundle provides Twig functions to add head tags from Twig templates:

```
{# Set tags #}
{% do add_head_tag('title', 'Hello World') %}
{% do add_head_tag('base', 'https://example.org') %}
{# you can also set meta tags with meta_ prefix, but it is easier with add_head_meta_tag function #}
{% do add_head_tag('meta_description', 'Lorem ipsum!') %}

{# Add meta tags #}
{% do add_head_meta_tag('description', 'Lorem ipsum!') %}
{% do add_head_meta_tag('og:title', 'Hello World') %}
{% do add_head_meta_tag('twitter:image', figure) %}

{# Add multiple tags at once #}
{# Pass as key => value or a AbstractHeadTag object #}
{# Value can be a string, null or a Contao Figure. If a Figure is passed, its image source will be used as the tag content. #}
{% do add_head_tags({
    'title': 'Hello World',
    'base': 'https://example.org',
    'meta_description': 'Lorem ipsum!',
    'meta_og:title': 'Hello World',
    'meta_twitter:image': figure,
}) %}

{# Shorthand for news #}
{%- do add_head_tags(get_head_news_tags(model, figure|default)) -%}
```

FunctionDescription`add_head_tag(name, value)`Add all kinds of head tag. Meta tag names must be prefixed with `meta_`, for example `meta_description` or `meta_og:title`.`add_head_meta_tag(name, value)`Shorthand for meta tags. The function adds the `meta_` prefix automatically.`add_head_tags(array)`Add multiple tags at once. Pass as key =&gt; value or a `AbstractHeadTag` object. Meta tags must be prefixed with meta when passed as key.`get_head_news_tags(model, figure)`Create an array of tags for news models. The function automatically adds og:title, og:description, og:url and og:image tags. Pass a figure to override default news article image.The `value` argument can be a string, `null` or a Contao `Figure`. If a `Figure` is passed, its image source is used as the tag content.

Integration
-----------

[](#integration)

Use head bundle api set in your code.

### Set head content

[](#set-head-content)

To set base, title, meta and link tags, use the `HtmlHeadTagManager` service:

```
use HeimrichHannot\HeadBundle\HeadTag\BaseTag;
use HeimrichHannot\HeadBundle\HeadTag\LinkTag;
use HeimrichHannot\HeadBundle\HeadTag\MetaTag;
use HeimrichHannot\HeadBundle\HeadTag\Meta\CharsetMetaTag;
use HeimrichHannot\HeadBundle\HeadTag\Meta\HttpEquivMetaTag;
use HeimrichHannot\HeadBundle\HeadTag\Meta\PropertyMetaTag;
use HeimrichHannot\HeadBundle\HeadTag\TitleTag;
use HeimrichHannot\HeadBundle\Manager\HtmlHeadTagManager;
use Symfony\Component\HttpFoundation\Request;

class SomeEventListener
{
    private HtmlHeadTagManager $headTagManager;

    public function updateBaseTag(Request $request): void
    {
        // Set base tag to null to remove it
        $this->headTagManager->setBaseTag(null);

        //Set base tag from object or url
        $this->headTagManager->setBaseTag(new BaseTag($request->getSchemeAndHttpHost()));
        $this->headTagManager->setBaseTag('https://example.org');
    }

    public function updatedTitleTag(): void
    {
        // Set title to "Hello World"
        $this->headTagManager->setTitleTag('Hello World');

        // Set title tag from object and adjust output format
        $this->headTagManager->setTitleTag(new TitleTag('Foo Bar', '%s | {{page::rootPageTitle}}'));
        // Will output: Foo Bar | My Great Website Page Title
    }

    public function setMetaTags(): void
    {
        // Add a new meta tag. If a tag with the same name already exists, it will be overridden
        $this->headTagManager->addMetaTag(new MetaTag('author', 'John Doe'));

        // Get an existing tag
        $description = ($tag = $this->headTagManager->getMetaTag('og:description')) ? $tag->getContent() : '';

        // Remove a tag
        $this->headTagManager->removeMetaTag('twitter:site');

        // Create a tag for property meta tags
        $this->headTagManager->addMetaTag(new PropertyMetaTag('og:type', 'article'));

        // Create a http-equiv tag
        $this->headTagManager->addMetaTag(new HttpEquivMetaTag('refresh', '30'));

        // Set a charset tag
        $this->headTagManager->addMetaTag(new CharsetMetaTag('UTF-8'));

        // Create tags without class (usefull when creating tags in a loop without custom checks)
        $this->headTagManager->addMetaTag(
            $this->headTagManager->getHeadTagFactory()->createMetaTag('description', 'Lorem ipsum!')
        );
        $this->headTagManager->addMetaTag(
            $this->headTagManager->getHeadTagFactory()->createTagByName('meta_og:url', 'https://example.org')
        );
    }

    public function setLinkTags(): void
    {
        // Add a new link tag. If a tag with the same name already exists, it will be overridden
        $this->headTagManager->addLinkTag(new LinkTag('next', 'https://example.org?page=2'));

        // Get an existing tag
        $this->headTagManager->getLinkTag('prev');

        // Remove a tag
        $this->headTagManager->removeLinkTag('prev');
    }
}
```

Developers
----------

[](#developers)

### Backend field

[](#backend-field)

Get tag options for a select field. If you want to define options by your own, prepend meta tag options with `meta_`.

```
use HeimrichHannot\HeadBundle\Helper\DcaHelper;

class HeadTagOptionsListener {
    private DcaHelper $dcaHelper;

    public function __invoke() {
        return $this->dcaHelper->getTagOptions([
            // filter: (array|null) If set, only tags fulfill given filters will be returned. See FILTER constants for available options. Default null
            'filter' => [DcaHelper::FILTER_META, DcaHelper::FILTER_TITLE],
            // skip_tags: (array) Skip specific tags. Default empty
            'skip_tag' => ['og:locale'],
        ]);
    }
}
```

Example how to evaluate field values:

```
use Contao\ContentModel;
use HeimrichHannot\HeadBundle\Manager\HtmlHeadTagManager;

class SomeEventListener {
    private HtmlHeadTagManager $headTagManager;

    public function __invoke(ContentModel $contentModel){
        $tag = $this->headTagManager->getHeadTagFactory()->createTagByName($contentModel->headTag);
        if ($tag) {
            $tag->setAttribute("content", $contentModel->headTagContent);
            $this->headTagManager->addTag($tag);
        }
    }
}
```

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance80

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 88% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~54 days

Recently: every ~41 days

Total

59

Last Release

46d ago

Major Versions

1.14.2 → 2.0.02026-05-18

PHP version history (7 changes)1.0.0PHP &gt;=5.6.0

1.0.5PHP ^5.6|^7.0

1.0.10PHP ^7.1

1.4.0PHP ^7.1|^8.0

1.5.0PHP ^7.1||^8.0

1.6.0PHP ^7.4 || ^8.0

2.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/28ad3224d8727b622ebd229840eea6b9dbcb83eb0bd609e6ce65b614830ff538?d=identicon)[digitales@heimrich-hannot.de](/maintainers/digitales@heimrich-hannot.de)

---

Top Contributors

[![koertho](https://avatars.githubusercontent.com/u/12064642?v=4)](https://github.com/koertho "koertho (88 commits)")[![ericges](https://avatars.githubusercontent.com/u/25957923?v=4)](https://github.com/ericges "ericges (8 commits)")[![PittRo](https://avatars.githubusercontent.com/u/51906753?v=4)](https://github.com/PittRo "PittRo (2 commits)")[![heimrich-hannot](https://avatars.githubusercontent.com/u/37208441?v=4)](https://github.com/heimrich-hannot "heimrich-hannot (1 commits)")[![vvohh](https://avatars.githubusercontent.com/u/75325799?v=4)](https://github.com/vvohh "vvohh (1 commits)")

---

Tags

contaophpseo

###  Code Quality

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/heimrichhannot-contao-head-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/heimrichhannot-contao-head-bundle/health.svg)](https://phpackages.com/packages/heimrichhannot-contao-head-bundle)
```

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[metamodels/core

MetaModels core

10156.4k68](/packages/metamodels-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
