Search by

numero2 / contao-opengraph3

numero2

Implementation of OpenGraph tags and X / Twitter Cards for Contao

Package info

github.com/numero2/contao-opengraph3

Type:contao-bundle

pkg:composer/numero2/contao-opengraph3

Statistics

Installs: 40 711

Dependents: 1

Suggesters: 1

Stars: 4

Open Issues: 0

v4.3.10 2026-05-21 06:31 UTC

README

Packagist Version License: LGPL v3

Implementation of OpenGraph tags and X / Twitter Cards for Contao. Read more

Requirements

For Contao 4.13 use version 4.x of this bundle.

Installation

Via Contao Manager or Composer:

composer require numero2/contao-opengraph3

Afterwards run a database update via the Contao Manager or the contao:migrate command.

Compatible bundles

By default the OpenGraph fields are attached to the site structure. The values of a page are used as fallback for all of its subpages, the values of the website root as fallback for the whole website.

Furthermore the fields are available for the following bundles. If a reader module of one of these bundles is placed on a page, the data of the displayed record takes precedence over the data of the page:

Bundle Reader module
news newsreader
calendar eventreader
faq faqreader
isotope iso_productreader
storelocator storelocator_details

The tags are added to the HtmlHeadBag and work with legacy as well as modern page layouts. Tags that have already been added by a template or another extension will not be overwritten.

Developer API

Adding support for your own reader module

Implement numero2\Opengraph3Bundle\OpenGraph\Provider\ProviderInterface and register the class as a service with autoconfiguration enabled:

// src/OpenGraph/MyProvider.php
namespace App\OpenGraph;

use App\Model\MyModel;
use Contao\Input;
use Contao\ModuleModel;
use numero2\Opengraph3Bundle\OpenGraph\OpenGraphReference;
use numero2\Opengraph3Bundle\OpenGraph\Provider\ProviderInterface;

class MyProvider implements ProviderInterface
{
    public function supports(ModuleModel $model): bool
    {
        return $model->type === 'my_reader';
    }

    public function getReference(ModuleModel $model): ?OpenGraphReference
    {
        if (!$record = MyModel::findByIdOrAlias(Input::get('auto_item'))) {
            return null;
        }

        // the default values are used for fields that are empty in the record
        return new OpenGraphReference($record, [
            'og_type' => 'article',
            'og_article_published_time' => $record->date,
        ]);
    }
}

To add the OpenGraph fields to your own table, call the following in your DCA file:

// contao/dca/tl_my_table.php
use numero2\Opengraph3Bundle\DataContainer\OpenGraphFields;

// add the legends before the "expert_legend" of the default palette and only allow the type "article"
OpenGraphFields::addToTable('tl_my_table', ['default' => 'expert_legend'], ['article']);

Using a record from your own controller

The numero2\Opengraph3Bundle\OpenGraph\OpenGraphManager service can be injected to set the record providing the OpenGraph data directly:

$this->openGraphManager->setReference(new OpenGraphReference($record, ['og_type' => 'article']));